Skip to content

fix: include file path in JSON parse errors for INPUT.json - #1339

Open
kuntal1461 wants to merge 1 commit into
apify:masterfrom
kuntal1461:fix/json-parse-error-file-path-1181
Open

fix: include file path in JSON parse errors for INPUT.json#1339
kuntal1461 wants to merge 1 commit into
apify:masterfrom
kuntal1461:fix/json-parse-error-file-path-1181

Conversation

@kuntal1461

Copy link
Copy Markdown

Fixes #1181

What changed

  • resolveInput() (apify actor call / apify task call path): bare JSON.parse now wrapped in try/catch that throws with the full file path in the message
  • getInputOverride() --input-file path (apify run --input-file): same fix — file path included in parse error
  • RunCommand (apify run with input schema): same fix — file path included in parse error; also cast inputJson to Record<string,unknown> after the array guard to fix a TypeScript spread error introduced by the unknown annotation
  • run.test.ts: fixed incorrect import { dirname } from 'node:path/win32'node:path (worked by accident on macOS, semantically wrong)

Tests added

  • resolve-input.test.ts — new test: getInputOverride with a malformed --input-file includes the file path in the error
  • resolve-input.test.ts — new resolveInput describe block: malformed INPUT.json in local KV store includes the file path
  • run.test.ts — new test: apify run with a malformed INPUT.json includes the path and the parse detail

Checklist

  • pnpm run lint — 0 warnings, 0 errors
  • pnpm run format — all files correctly formatted
  • pnpm run build — clean
  • pnpm run test:local — 420/420 non-Python tests pass (2 [python] failures are pre-existing env issue: Python 3.14 Homebrew externally-managed-environment, unrelated to this change)

- Wrap JSON.parse in resolveInput() (apify actor call path) with try/catch that includes the full file path
- Wrap JSON.parse in getInputOverride() --input-file path with the same fix
- Wrap JSON.parse in RunCommand (apify run path) with try/catch + file path
- Cast inputJson to Record<string,unknown> after array guard to satisfy TS
- Fix incorrect node:path/win32 import in run.test.ts (should be node:path)
- Add tests for all three JSON parse error paths
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adding filepath to Error messages related to invalid JSON files

2 participants