Skip to content

Commit

Permalink
fix: improve compile log error if bad syntax on the string
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio Moreno committed Apr 8, 2021
1 parent 7c0a52f commit 9b2705f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 5 additions & 1 deletion packages/cli/src/api/__snapshots__/compile.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`compile should report failed message on error 1`] = `Can't parse message. Please check correct syntax: "{value, plural, one {Book} other {Books"`;
exports[`compile should report failed message on error 1`] = `
Can't parse message. Please check correct syntax: "{value, plural, one {Book} other {Books"
Messageformat-parser trace: Expected "#", "{", "}", doubled apostrophe, escaped string, or plain char but end of input found.
`;
exports[`createCompiledCatalog options.compilerBabelOptions by default should return catalog without ASCII chars 1`] = `/*eslint-disable*/module.exports={messages:{"Hello":"Alohà"}};`;
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/api/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,12 @@ function buildExportStatement(expression, namespace: CompiledCatalogNamespace) {
*/
export function compile(message: string) {
let tokens

try {
tokens = parse(message)
} catch (e) {
throw new Error(
`Can't parse message. Please check correct syntax: "${message}"`
`Can't parse message. Please check correct syntax: "${message}" \n \n Messageformat-parser trace: ${e.message}`,
)
}
const ast = processTokens(tokens)
Expand Down

1 comment on commit 9b2705f

@vercel
Copy link

@vercel vercel bot commented on 9b2705f Apr 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.