getodk / central-frontend

Vue.js based frontend for ODK Central

Home Page:https://docs.getodk.org/central-intro/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

destructure.js throws error for JSON structure mismatch

matthew-white opened this issue · comments

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.