parse_error.go 907 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package ini
  2. import "fmt"
  3. const (
  4. // ErrCodeParseError is returned when a parsing error
  5. // has occurred.
  6. ErrCodeParseError = "INIParseError"
  7. )
  8. // ParseError is an error which is returned during any part of
  9. // the parsing process.
  10. type ParseError struct {
  11. msg string
  12. }
  13. // NewParseError will return a new ParseError where message
  14. // is the description of the error.
  15. func NewParseError(message string) *ParseError {
  16. return &ParseError{
  17. msg: message,
  18. }
  19. }
  20. // Code will return the ErrCodeParseError
  21. func (err *ParseError) Code() string {
  22. return ErrCodeParseError
  23. }
  24. // Message returns the error's message
  25. func (err *ParseError) Message() string {
  26. return err.msg
  27. }
  28. // OrigError return nothing since there will never be any
  29. // original error.
  30. func (err *ParseError) OrigError() error {
  31. return nil
  32. }
  33. func (err *ParseError) Error() string {
  34. return fmt.Sprintf("%s: %s", err.Code(), err.Message())
  35. }