Skip to content

Report a malformed JSON import instead of crashing [patch] - #208

Merged
matt-edmondson merged 2 commits into
mainfrom
fix/import-malformed-json
Oct 12, 2026
Merged

matt-edmondson merged 2 commits into
mainfrom
fix/import-malformed-json

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Summary

Import.ImportJson caught nothing, so any JSON file that failed to deserialize (an object at the root, a truncated array, "FileSizeBytes":"abc") ended the process with a stack trace, and ended the interactive menu session along with it.

ImportJson now catches JsonException, plus the ArgumentException a semantic type throws when validation fails. It prints Error: <file> is not a valid ImageDescriber JSON export: <message> and returns null, so Run sets Failed and returns before MergeEntries or Program.Settings.Save(). The store is left untouched and the exit code is 1. This matches how the CSV path already handles malformed rows.

Tests

  • New data-driven test ImportTests.RunReportsAMalformedJsonFileWithoutThrowingOrChangingTheStore covers the three inputs from the acceptance criteria. For each one it asserts that the run fails without throwing, adds nothing to the store, and prints an error that names the file.
  • With the fix reverted, all three rows fail with the original JsonException. With the fix, they pass.
  • Full suite: 120 passed, 1 skipped (ScanForImagesSkipsUnreadableSubdirectories, which is inconclusive when run as root).

Fixes #172

🤖 Generated with Claude Code

https://claude.ai/code/session_01EizTraGREbkNoiWDb3o9eC


Generated by Claude Code

ImportJson caught nothing, so a truncated file, an object instead of an array,
or a field of the wrong type ended the process with a stack trace (and ended
the interactive menu with it). It now catches JsonException and the
ArgumentException a semantic type throws on validation, prints an error
naming the file, and returns null so Run fails before anything is merged or
saved, the way the CSV path already skips bad rows.

Fixes #172

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EizTraGREbkNoiWDb3o9eC
A relative KnownPaths entry makes the AbsoluteFilePath conversion throw
ArgumentException, which is the second catch in ImportJson; the test now
exercises it alongside the three JsonException cases.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EizTraGREbkNoiWDb3o9eC
@sonarqubecloud

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit ad9235c into main Oct 12, 2026
14 checks passed
@matt-edmondson
matt-edmondson deleted the fix/import-malformed-json branch October 12, 2026 23:09
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.

Importing a JSON file that isn't a valid description array crashes Import with an unhandled JsonException

2 participants