k8s.io/kube-openapi@v0.0.0-20240228011516-70dd3763d340/pkg/util/proto/validation/errors.go (about)

     1  /*
     2  Copyright 2017 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package validation
    18  
    19  import (
    20  	"fmt"
    21  )
    22  
    23  type errors struct {
    24  	errors []error
    25  }
    26  
    27  func (e *errors) Errors() []error {
    28  	return e.errors
    29  }
    30  
    31  func (e *errors) AppendErrors(err ...error) {
    32  	e.errors = append(e.errors, err...)
    33  }
    34  
    35  type ValidationError struct {
    36  	Path string
    37  	Err  error
    38  }
    39  
    40  func (e ValidationError) Error() string {
    41  	return fmt.Sprintf("ValidationError(%s): %v", e.Path, e.Err)
    42  }
    43  
    44  type InvalidTypeError struct {
    45  	Path     string
    46  	Expected string
    47  	Actual   string
    48  }
    49  
    50  func (e InvalidTypeError) Error() string {
    51  	return fmt.Sprintf("invalid type for %s: got %q, expected %q", e.Path, e.Actual, e.Expected)
    52  }
    53  
    54  type MissingRequiredFieldError struct {
    55  	Path  string
    56  	Field string
    57  }
    58  
    59  func (e MissingRequiredFieldError) Error() string {
    60  	return fmt.Sprintf("missing required field %q in %s", e.Field, e.Path)
    61  }
    62  
    63  type UnknownFieldError struct {
    64  	Path  string
    65  	Field string
    66  }
    67  
    68  func (e UnknownFieldError) Error() string {
    69  	return fmt.Sprintf("unknown field %q in %s", e.Field, e.Path)
    70  }
    71  
    72  type InvalidObjectTypeError struct {
    73  	Path string
    74  	Type string
    75  }
    76  
    77  func (e InvalidObjectTypeError) Error() string {
    78  	return fmt.Sprintf("unknown object type %q in %s", e.Type, e.Path)
    79  }