Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Improve i18n middleware error messages #882

Merged
merged 3 commits into from
Jan 28, 2018
Merged

Conversation

stanislas-m
Copy link
Member

* Wrap parsing errors
* Wrap Box errors
* Log missing or empty locale files as a Warning, not an Error (fix #878)
@stanislas-m stanislas-m requested a review from markbates January 27, 2018 08:16
@@ -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)
Copy link
Member

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. :)

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)
Copy link
Member

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. :)

log.Fatal(err)
return errors.WithStack(err)
wErr := errors.Wrapf(err, "Unable to read locale file %s", path)
log.Fatal(wErr)
Copy link
Member

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.

@stanislas-m
Copy link
Member Author

@markbates Thanks, it should be ok now. :)

@markbates markbates added this to the 0.11.0 milestone Jan 28, 2018
@markbates markbates merged commit 44bde5b into development Jan 28, 2018
@markbates markbates deleted the improve-i18n-errors branch January 28, 2018 18:16
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants