feat: Improve error handling with custom error types and detailed messages

This commit is contained in:
2024-11-11 15:01:20 +02:00
parent 6346c9a829
commit 2bb8589eb7
3 changed files with 148 additions and 22 deletions

28
config/errors.go Normal file
View 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)
}