go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/config/impl/erroring/erroring.go (about)

     1  // Copyright 2015 The LUCI Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  // Package erroring implements a backend that always returns an error for all
    16  // of its calls.
    17  package erroring
    18  
    19  import (
    20  	"context"
    21  
    22  	"go.chromium.org/luci/config"
    23  )
    24  
    25  // New creates a new erroring interface. This interface will always return an
    26  // error for every API call.
    27  //
    28  // The supplied error must not be nil. If it is, New will panic.
    29  func New(err error) config.Interface {
    30  	if err == nil {
    31  		panic("error cannot be nil")
    32  	}
    33  	return erroringInterface{err}
    34  }
    35  
    36  type erroringInterface struct {
    37  	err error
    38  }
    39  
    40  func (i erroringInterface) GetConfig(ctx context.Context, configSet config.Set, path string, metaOnly bool) (*config.Config, error) {
    41  	return nil, i.err
    42  }
    43  
    44  func (i erroringInterface) GetConfigs(ctx context.Context, configSet config.Set, filter func(path string) bool, metaOnly bool) (map[string]config.Config, error) {
    45  	return nil, i.err
    46  }
    47  
    48  func (i erroringInterface) GetProjectConfigs(ctx context.Context, path string, metaOnly bool) ([]config.Config, error) {
    49  	return nil, i.err
    50  }
    51  
    52  func (i erroringInterface) GetProjects(ctx context.Context) ([]config.Project, error) {
    53  	return nil, i.err
    54  }
    55  
    56  func (i erroringInterface) ListFiles(ctx context.Context, configSet config.Set) ([]string, error) {
    57  	return nil, i.err
    58  }
    59  
    60  func (i erroringInterface) Close() error {
    61  	return nil
    62  }