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

destructure.js throws error for JSON structure mismatch #858

Open
matthew-white opened this issue Sep 14, 2023 · 0 comments
Open

destructure.js throws error for JSON structure mismatch #858

matthew-white opened this issue Sep 14, 2023 · 0 comments
Labels
dx Developer workflow, automated checks i18n Internationalization

Comments

@matthew-white
Copy link
Member

For a JSON file of translations in the transifex/ directory (e.g., transifex/strings_fr.json), destructure.js expects that the structure of the file exactly matches the structure of the source file (transifex/strings_en.json). If it doesn't, it throws an error:

central-frontend/bin/util/transifex.js:877
      const value = this.get(k).toJSON(k);
                               ^

TypeError: Cannot read properties of undefined (reading 'toJSON')
    at Translations.toJSON (central-frontend/bin/util/transifex.js:877:32)
    at JSON.stringify (<anonymous>)
    at writeTranslations (central-frontend/bin/util/transifex.js:1059:25)
    at Object.<anonymous> (central-frontend/bin/transifex/destructure.js:25:3)

This error comes up in practice. If you don't pull the latest commit on the master branch before pulling translations, then there may be a mismatch in structure. Currently, the error doesn't explain the issue, but it'd be helpful if it did:

  • Translations.toJSON() could check whether this.get(k) is undefined. It may have to do this in a few places.
  • Probably better: writeTranslations() could check for this upfront by comparing the structure of source and translated, maybe using translations.walk().
  • Alternatively, I was thinking that destructure.js could check whether HEAD is ahead of origin/master. However, I'm now thinking that even then, there could be ways for this error to show up. Examples: the working directory isn't clean; you're on a local branch that's made changes to transifex/strings_en.json.
@matthew-white matthew-white added infrastructure Changes to core libraries or setup i18n Internationalization labels Sep 14, 2023
@matthew-white matthew-white added dx Developer workflow, automated checks and removed infrastructure Changes to core libraries or setup labels Nov 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dx Developer workflow, automated checks i18n Internationalization
Projects
None yet
Development

No branches or pull requests

1 participant