opral / inlang-message-sdk

0 stars 0 forks source link

Better error message for invalid messages json file #87

Closed thenbe closed 3 weeks ago

thenbe commented 3 weeks ago

Current

These two scenarios result in the same error being logged ("missing messages") when running npx vite dev.

  1. An invalid pathPattern:
    "plugin.inlang.json": {
        "pathPattern": "./does/not/exist/{languageTag}.json"
    }
  1. An invalid en.json file:
{
    // this json file is not valid because it contains a comment
    "foo": "bar"
}

Expected

The second scenario should provide a better error message to indicate the error is the result of invalid json.

Repro

My setup was similar to this example

jldec commented 3 weeks ago

@loris.sigrist
I can't repro this but perhaps I'm not doing it right. Moving the issue to paraglide

Since https://github.com/opral/monorepo/pull/2681 JSON errors should be propagated
This is working for me with the example repo linked above, when i change en.json to introduce a JSON error

$ p paraglide-js compile --project ./project.inlang/
ℹ [paraglide] Compiling inlang project at "./project.inlang/".                                                                                                          
Using existing cloned repo

 WARN  The project has errors:                                                                                                                                           

 ERROR  An error occured in loadMessages() caused by SyntaxError: Expected property name or '}' in JSON at position 3.                                                   

  at node_modules/.pnpm/@inlang+paraglide-js@1.9.1/node_modules/@inlang/paraglide-js/dist/index.js:9234:34

~/opral/paraglide-sveltekit-example$ 

File not found errors are not considered errors a.t.m and the message file will be auto-created if missing, on first write. There is an issue to improve this. MESDK-99 (https://github.com/opral/inlang-message-sdk/issues/60)

jldec commented 3 weeks ago

@thenbe could you please provide more specific steps to reproduce this (ideally link to a test repo on github) and your project.inlang/settings.json file.

thenbe commented 3 weeks ago

Here are the repro steps:

git clone https://github.com/LorisSigrist/paraglide-sveltekit-example.git
cd paraglide-sveltekit-example
pnpm install
echo '// i am a comment' >> messages/en.json
pnpm vite dev

And this is the full error message:

WARN  No messages found - Skipping compilation into ./src/lib/paraglide
jldec commented 3 weeks ago

@loris.sigrist i can confirm

$ echo '// i am a comment' >> messages/en.json
pnpm vite dev
Using existing cloned repo

 WARN  No messages found - Skipping compilation into ./src/lib/paraglide                                                                                 

  VITE v5.2.12  ready in 3182 ms
$ pnpm paraglide-js compile --project project.inlang/
ℹ [paraglide] Compiling inlang project at "project.inlang/".                                                                                            
Using existing cloned repo

 WARN  The project has errors:                                                                                                                           

 ERROR  An error occured in loadMessages() caused by SyntaxError: Expected property name or '}' in JSON at position 3.                                   

  at node_modules/.pnpm/@inlang+paraglide-js@1.9.1/node_modules/@inlang/paraglide-js/dist/index.js:9234:34

$