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
Summary
nam::get_dsp(const std::filesystem::path&)lets JSON parser exceptions escape when a.namfile is empty or contains malformed JSON. Consumers that handle Core's normalstd::runtime_errorload 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.namObserved on macOS with AppleClang 16:
The process exits with status 134.
Root cause
The path overload in
NAM/get_dsp.cppreads directly into anlohmann::jsonvalue:std::ifstream i(config_filename); nlohmann::json j; i >> j;An empty or malformed file makes
operator>>thrownlohmann::json::parse_error. That exception is not translated to thestd::runtime_errorused by the surrounding file/model validation paths, so it escapes consumers such as NeuralAmpModelerPlugin's staged model loader.Current
origin/mainstill has the unguarded parse.Expected behavior
Loading an empty or malformed
.namfile 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..namfile could not be parsed (and ideally includes the path and parser detail)..namfile and malformed JSON.Upstream context: sdatkinson/NeuralAmpModelerPlugin#569