Skip to content

[BUG] get_dsp(path) lets JSON parse errors terminate consumers #314

Description

@sdatkinson

Summary

nam::get_dsp(const std::filesystem::path&) lets JSON parser exceptions escape when a .nam file is empty or contains malformed JSON. Consumers that handle Core's normal std::runtime_error load failures can therefore terminate instead of reporting a recoverable model-load error.

This is the upstream cause of sdatkinson/NeuralAmpModelerPlugin#569.

Reproduction

On current main (3cde95c354d5ba6da01316cad90b05cfc4855053):

cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug
cmake --build build --target loadmodel
touch /tmp/empty.nam
build/tools/loadmodel /tmp/empty.nam

Observed on macOS with AppleClang 16:

Loading model [/tmp/empty.nam]
libc++abi: terminating due to uncaught exception of type nlohmann::json_abi_v3_12_0::detail::parse_error: [json.exception.parse_error.101] parse error at line 1, column 1: attempting to parse an empty input; check that your input string or stream contains the expected JSON

The process exits with status 134.

Root cause

The path overload in NAM/get_dsp.cpp reads directly into a nlohmann::json value:

std::ifstream i(config_filename);
nlohmann::json j;
i >> j;

An empty or malformed file makes operator>> throw nlohmann::json::parse_error. That exception is not translated to the std::runtime_error used by the surrounding file/model validation paths, so it escapes consumers such as NeuralAmpModelerPlugin's staged model loader.

Current origin/main still has the unguarded parse.

Expected behavior

Loading an empty or malformed .nam file should fail through Core's recoverable model-load error path, with a useful message, rather than allowing a JSON implementation exception to escape and terminate a consumer.

Acceptance criteria

  • get_dsp(path) reports empty and malformed JSON as a recoverable load failure consistent with the rest of the API.
  • The error message identifies that the .nam file could not be parsed (and ideally includes the path and parser detail).
  • Tests cover at least an empty .nam file and malformed JSON.

Upstream context: sdatkinson/NeuralAmpModelerPlugin#569

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions