...

Source file src/github.com/chaos-mesh/chaos-mesh/controllers/chaosimpl/utils/error.go

Documentation: github.com/chaos-mesh/chaos-mesh/controllers/chaosimpl/utils

     1  // Copyright 2021 Chaos Mesh 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  
    16  package utils
    17  
    18  import "fmt"
    19  
    20  type failToFindContainer struct {
    21  	namespace     string
    22  	name          string
    23  	containerName string
    24  
    25  	err error
    26  }
    27  
    28  func NewFailToFindContainer(namespace string, name string, containerName string, err error) error {
    29  	return &failToFindContainer{
    30  		namespace,
    31  		name,
    32  		containerName,
    33  		err,
    34  	}
    35  }
    36  
    37  func (e *failToFindContainer) Error() string {
    38  	if e.err == nil {
    39  		return fmt.Sprintf("fail to find container %s on pod %s/%s", e.containerName, e.namespace, e.name)
    40  	}
    41  
    42  	return e.err.Error()
    43  }
    44  
    45  func IsFailToGet(e error) bool {
    46  	switch e.(type) {
    47  	case *failToFindContainer:
    48  		return true
    49  	default:
    50  		return false
    51  	}
    52  }
    53