Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not blow up the whole page if a variable is missing ? #1853

Closed
gzurbach opened this issue Mar 28, 2024 · 2 comments · Fixed by #1887
Closed

Do not blow up the whole page if a variable is missing ? #1853

gzurbach opened this issue Mar 28, 2024 · 2 comments · Fixed by #1887

Comments

@gzurbach
Copy link
Contributor

gzurbach commented Mar 28, 2024

This issue happens to me all the time and I wonder if it should be that way.

If I declare a string that contains a variable, but for any reason the variable is not provided, ember-intl throws an error and the entire rendering of the page breaks:

The intl string context variable "firstName" was not provided to the string "Hello {firstName}"

I can see the behavior being desirable in development builds, but in production? It seems overkill. A simple warning would be enough.

We handle 13 locales and download translations asynchronously, which can sometimes result in out-of-sync translations lasting for several days. Consider a scenario where we make a code change to eliminate a variable from a string. We are unable to deploy the change until that variable has been removed from every locale. Otherwise, the page won't render properly in any language where that variable remains present.

Is that something we could consider changing?

@ijlee2
Copy link
Contributor

ijlee2 commented Apr 2, 2024

Hi, @gzurbach. Thanks for providing your feedback. The error message is coming from @formatjs/intl-messageformat.

For ember-intl@6.5.0 and above, you can find the file addon/-private/utils/formatjs.ts in your node_modules folder. Then, you can patch this file (in particular, the function onFormatjsIntlError()) so that v6.x addresses your case:

export function onFormatjsIntlError(error: IntlError): void {
  switch (error.code) {
+     case IntlErrorCode.FORMAT_ERROR: {
+       // Do nothing
+       break;
+     }
+ 
    case IntlErrorCode.MISSING_TRANSLATION: {
      // Do nothing
      break;
    }

    default: {
      throw error;
    }
  }
}

If you are on a version between 6.1.0 and 6.4.1, you can find the corresponding code in addon/services/intl.js (i.e. patch this file instead). The error codes are briefly described in https://github.com/formatjs/formatjs/blob/%40formatjs/intl%402.10.1/website/docs/guides/develop.md#format_error.

I don't know yet what the default for error handling for 7.x will be, so I could only provide a temporary patch as a possible solution. :)

@gzurbach
Copy link
Contributor Author

gzurbach commented Apr 9, 2024

Thank you for your thorough response, @ijlee2. I appreciate it. I should clarify that I am currently running ember-intl@6.5.3.

I prefer not to resort to cloning or branching the library for this particular issue. My intention in reaching out was more of a suggestion for potential inclusion in a future version of ember-intl.

The proposal:

  • For development builds: throw any FORMAT_ERROR.
  • For production builds: consider displaying a warning or gracefully ignoring the error.

Thank you for your consideration!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants