errors.go 820 B

1234567891011121314151617181920212223242526272829303132
  1. // Copyright 2018-present the CoreDHCP Authors. All rights reserved
  2. // This source code is licensed under the MIT license found in the
  3. // LICENSE file in the root directory of this source tree.
  4. package config
  5. import (
  6. "fmt"
  7. )
  8. // ConfigError is an error type returned upon configuration errors.
  9. type ConfigError struct {
  10. err error
  11. }
  12. // ConfigErrorFromString returns a ConfigError from the given error string.
  13. func ConfigErrorFromString(format string, args ...interface{}) *ConfigError {
  14. return &ConfigError{
  15. err: fmt.Errorf(format, args...),
  16. }
  17. }
  18. // ConfigErrorFromError returns a ConfigError from the given error object.
  19. func ConfigErrorFromError(err error) *ConfigError {
  20. return &ConfigError{
  21. err: err,
  22. }
  23. }
  24. func (ce ConfigError) Error() string {
  25. return fmt.Sprintf("error parsing config: %v", ce.err)
  26. }