feat: Improve error handling with custom error types and detailed messages
This commit is contained in:
28
config/errors.go
Normal file
28
config/errors.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package config
|
||||
|
||||
import "fmt"
|
||||
|
||||
// ConfigError represents a configuration error
|
||||
type ConfigError struct {
|
||||
Param string
|
||||
Err error
|
||||
}
|
||||
|
||||
func (e *ConfigError) Error() string {
|
||||
return fmt.Sprintf("configuration error for %s: %v", e.Param, e.Err)
|
||||
}
|
||||
|
||||
func (e *ConfigError) Unwrap() error {
|
||||
return e.Err
|
||||
}
|
||||
|
||||
// ValidationError represents a validation error
|
||||
type ValidationError struct {
|
||||
Param string
|
||||
Value string
|
||||
Reason string
|
||||
}
|
||||
|
||||
func (e *ValidationError) Error() string {
|
||||
return fmt.Sprintf("invalid value '%s' for %s: %s", e.Value, e.Param, e.Reason)
|
||||
}
|
||||
Reference in New Issue
Block a user