-
-
Notifications
You must be signed in to change notification settings - Fork 579
Improve i18n middleware error messages #882
Conversation
stanislas-m
commented
Jan 27, 2018
- Wrap parsing errors
- Wrap Box errors
- Log missing or empty locale files as a Warning, not an Error (fix 500 - ERROR! no supported languages found #878)
* Wrap parsing errors * Wrap Box errors * Log missing or empty locale files as a Warning, not an Error (fix #878)
middleware/i18n/i18n.go
Outdated
@@ -43,15 +43,20 @@ func (t *Translator) Load() error { | |||
return t.Box.Walk(func(path string, f packr.File) error { | |||
b, err := t.Box.MustBytes(path) | |||
if err != nil { | |||
log.Fatal(err) | |||
return errors.WithStack(err) | |||
wErr := errors.Wrapf(err, "Unable to read locale file %s", path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error messages in Go are suppose to start with a lower case letter. I have no idea why. :)
middleware/i18n/i18n.go
Outdated
return i18n.ParseTranslationFileBytes(fmt.Sprintf("%sbuff%s", dir, base), b) | ||
err = i18n.ParseTranslationFileBytes(fmt.Sprintf("%sbuff%s", dir, base), b) | ||
if err != nil { | ||
return errors.Wrapf(err, "Unable to parse locale file %s", base) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error messages in Go are suppose to start with a lower case letter. I have no idea why. :)
middleware/i18n/i18n.go
Outdated
log.Fatal(err) | ||
return errors.WithStack(err) | ||
wErr := errors.Wrapf(err, "Unable to read locale file %s", path) | ||
log.Fatal(wErr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this sounds silly, since there was already a log.Fatal
in this code, but shouldn't we not do that since it stops execution of the app? In theory the return
on the next line never gets called.
@markbates Thanks, it should be ok now. :) |