...

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