errors.go 869 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package errors
  2. import (
  3. stderrors "errors"
  4. "fmt"
  5. )
  6. // Standard errors that can be used across packages
  7. var (
  8. ErrNotFound = stderrors.New("resource not found")
  9. ErrInvalidInput = stderrors.New("invalid input")
  10. ErrUnauthorized = stderrors.New("unauthorized")
  11. ErrInternalServer = stderrors.New("internal server error")
  12. ErrDatabaseOperation = stderrors.New("database operation failed")
  13. )
  14. // ConfigError represents a configuration-related error
  15. type ConfigError struct {
  16. Section string
  17. Err error
  18. }
  19. func (e *ConfigError) Error() string {
  20. return fmt.Sprintf("configuration error in %s: %v", e.Section, e.Err)
  21. }
  22. func (e *ConfigError) Unwrap() error {
  23. return e.Err
  24. }
  25. // NewConfigError creates a new ConfigError
  26. func NewConfigError(section string, err error) *ConfigError {
  27. return &ConfigError{
  28. Section: section,
  29. Err: err,
  30. }
  31. }