fix: Friendly error messages for null and undefined values inside message files (#1041)
Co-authored-by: windmillcode0 <michaelodumosu57@gmail.com>
This commit is contained in:
@@ -161,4 +161,17 @@ describe('Built Tools', () => {
|
||||
);
|
||||
expect(mockWriteFile).toBeCalledWith('output.d.ts', expectedDts, 'utf8');
|
||||
});
|
||||
|
||||
it('should throw an error if messages file contains null or undefined', async () => {
|
||||
const invalidFileContent = stringifyYAML({
|
||||
simple: 'example',
|
||||
invalidField: null,
|
||||
});
|
||||
|
||||
mockReadFile.mockResolvedValue(invalidFileContent);
|
||||
|
||||
await expect(parseMessagesFile('invalid.yml')).rejects.toThrowError(
|
||||
'Messages file should not contain `null` (found at "invalidField")',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -166,6 +166,11 @@ function _parseMessagesObject(
|
||||
];
|
||||
}
|
||||
case 'object':
|
||||
if ([null, undefined].includes(object)) {
|
||||
throw new Error(
|
||||
`Messages file should not contain \`${object}\` (found at "${path.join('.')}")`,
|
||||
);
|
||||
}
|
||||
if (Array.isArray(object))
|
||||
return object.flatMap((item, i) =>
|
||||
_parseMessagesObject(path.concat(String(i)), item, depth + 1),
|
||||
|
||||
Reference in New Issue
Block a user