gitee.com/sy_183/go-common@v1.0.5-0.20231205030221-958cfe129b47/config/error.go (about)

     1  package config
     2  
     3  type ErrorType int
     4  
     5  const (
     6  	// ParseError occurs when an error occurs in the configuration parsing
     7  	ParseError = ErrorType(iota)
     8  
     9  	// CheckError occurs when an error occurs in the configuration checking
    10  	CheckError
    11  
    12  	// ReloadParseError occurs when an error occurs in the configuration
    13  	// reloaded and parsing
    14  	ReloadParseError
    15  
    16  	// ReloadCheckError occurs when an error occurs in the configuration
    17  	// reloaded and checking
    18  	ReloadCheckError
    19  )
    20  
    21  // Type method return the name of error type, If the error type is undefined, return
    22  // UNKNOWN_ERROR
    23  func (t ErrorType) Type() string {
    24  	switch t {
    25  	case ParseError:
    26  		return "PARSE_ERROR"
    27  	case CheckError:
    28  		return "CHECK_ERROR"
    29  	case ReloadParseError:
    30  		return "RELOAD_PARSE_ERROR"
    31  	case ReloadCheckError:
    32  		return "RELOAD_CHECK_ERROR"
    33  	default:
    34  		return "UNKNOWN_ERROR"
    35  	}
    36  }
    37  
    38  type Error struct {
    39  	Type ErrorType
    40  	Err  error
    41  }
    42  
    43  func (e Error) Error() string {
    44  	return e.Type.Type() + ": " + e.Err.Error()
    45  }