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 whetherthis.get(k)
isundefined
. It may have to do this in a few places.- Probably better:
writeTranslations()
could check for this upfront by comparing the structure ofsource
andtranslated
, maybe usingtranslations.walk()
. - Alternatively, I was thinking that destructure.js could check whether
HEAD
is ahead oforigin/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.