Skip to content

Integration tests: JSON errors lack field/line context #208

@nclack

Description

@nclack

Problem

When an integration test fails due to a JSON metadata mismatch, the error message provides no indication of which field caused the failure:

[json.exception.type_error.302] type must be string, but is number

This happens because tests use implicit nlohmann::json conversions (e.g. unit = axes[2]["unit"]) that throw a raw json::type_error or json::out_of_range before any EXPECT macro runs. The generic catch (const std::exception& e) in main() only prints e.what(), which has no file, line, or field name.

Narrowing down these failures currently requires attaching a debugger.

Affected tests

Every integration test that calls verify_group_metadata or verify_array_metadata — at least 10 files.

Suggested fix

Replace bare implicit conversions with .value() + EXPECT so failures report context:

// Before (throws raw json exception, no context):
unit = axes[2]["unit"];

// After (EXPECT prints file:line and field name on mismatch):
EXPECT(axes[2].contains("unit"), "Missing 'unit' on axis ", axes[2]["name"]);
unit = axes[2]["unit"].get<std::string>();

Or use axes[2].value("unit", "") to avoid the throw entirely, then check with EXPECT.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions