♻️ Use defined errors
This commit is contained in:
parent
5b60305de7
commit
2d68691408
5 changed files with 34 additions and 20 deletions
|
|
@ -56,12 +56,12 @@ func (m Meta) MarshalText() ([]byte, error) {
|
|||
|
||||
func (m *Meta) UnmarshalText(in []byte) error {
|
||||
if len(in) == 0 {
|
||||
return errors.New("Unable to Unmarshal empty string")
|
||||
return newParsingError(errors.New("Unable to Unmarshal empty string"))
|
||||
}
|
||||
re := regexp.MustCompile("(?s)^@([^ ]+) (.*)( @end)?$")
|
||||
match := re.FindSubmatch(in)
|
||||
if len(match) == 0 {
|
||||
return fmt.Errorf("Failed to match %s", in)
|
||||
return newParsingError(fmt.Errorf("Failed to match %s", in))
|
||||
}
|
||||
m.Key = string(match[1])
|
||||
return m.processMeta(match[2])
|
||||
|
|
@ -69,11 +69,11 @@ func (m *Meta) UnmarshalText(in []byte) error {
|
|||
|
||||
func (m *Meta) processMeta(in []byte) error {
|
||||
if len(in) == 0 {
|
||||
return errors.New("No value found")
|
||||
return newParsingError(errors.New("No value found"))
|
||||
}
|
||||
s := strings.TrimSpace(string(in))
|
||||
if len(s) == 0 {
|
||||
return errors.New("No value found")
|
||||
return newParsingError(errors.New("No value found"))
|
||||
}
|
||||
yesno := regexp.MustCompile("^(y|Y|yes|Yes|YES|n|N|no|No|NO|true|True|TRUE|false|False|FALSE|on|On|ON|off|Off|OFF)$")
|
||||
yes := regexp.MustCompile("^(y|Y|yes|Yes|YES|true|True|TRUE|on|On|ON)$")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue