What happened?
If ~/.pi/agent/models.json has invalid JSON, pi exits with a raw JSON.parse stack trace and does not mention models.json.
> pi
<anonymous_script>:20
i}
^
SyntaxError: Expected ',' or '}' after property value in JSON at position 524 (line 20 column 1)
at JSON.parse (<anonymous>)
at migrateModelsJsonConfigValues (.../dist/migrations.js:131:25)
at migrateExplicitEnvVarConfigValues (.../dist/migrations.js:173:70)
at runMigrations (.../dist/migrations.js:391:5)
at main (.../dist/main.js:420:79)
The normal ModelRegistry.loadCustomModels() path already reports malformed models.json with the file path. This seems to happen earlier, in the config env reference migration added for #5095 , where migrateModelsJsonConfigValues() parses models.json directly.
I’d be happy to send a PR for this.
I think the fix is to wrap the migrateModelsJsonConfigValues() parse path in the same style as ModelRegistry.loadCustomModels(): catch SyntaxError, include the resolved models.json path in the error message.
Steps to reproduce
- Add invalid JSON to
~/.pi/agent/models.json
- Run
pi
Expected behavior
The error should say which file failed to parse, e.g.
Error: models.json error: Failed to parse models.json: Expected ',' or '}' after property value in JSON at position 524 (line 20 column 1)
File: /home/user/.pi/agent/models.json
Version
0.78.1
What happened?
If
~/.pi/agent/models.jsonhas invalid JSON,piexits with a rawJSON.parsestack trace and does not mentionmodels.json.> pi <anonymous_script>:20 i} ^ SyntaxError: Expected ',' or '}' after property value in JSON at position 524 (line 20 column 1) at JSON.parse (<anonymous>) at migrateModelsJsonConfigValues (.../dist/migrations.js:131:25) at migrateExplicitEnvVarConfigValues (.../dist/migrations.js:173:70) at runMigrations (.../dist/migrations.js:391:5) at main (.../dist/main.js:420:79)The normal ModelRegistry.loadCustomModels() path already reports malformed models.json with the file path. This seems to happen earlier, in the config env reference migration added for #5095 , where migrateModelsJsonConfigValues() parses models.json directly.
I’d be happy to send a PR for this.
I think the fix is to wrap the migrateModelsJsonConfigValues() parse path in the same style as ModelRegistry.loadCustomModels(): catch SyntaxError, include the resolved models.json path in the error message.
Steps to reproduce
~/.pi/agent/models.jsonpiExpected behavior
The error should say which file failed to parse, e.g.
Version
0.78.1