make-initrd-ng: also print json itself if it fails to parse

The current error message is hard to debug because the error is in the
nix store:

> Error: failed to parse JSON in
"/build/.attr-1s42g1c76fxb77skzq0b4wdhcrg8jmzb54czmxvh1qm7psgsbcni"
>
> Caused by:
> missing field `source` at line 1 column 102
>
> Location:
> src/main.rs:329:10
This commit is contained in:
Jörg Thalheim 2024-08-02 09:43:39 +02:00
parent 1318ddf6f3
commit 3de4714572

View File

@ -326,7 +326,12 @@ fn main() -> eyre::Result<()> {
let contents =
fs::read(&args[1]).wrap_err_with(|| format!("failed to open file {:?}", &args[1]))?;
let input = serde_json::from_slice::<Vec<StoreInput>>(&contents)
.wrap_err_with(|| format!("failed to parse JSON in {:?}", &args[1]))?;
.wrap_err_with(|| {
let text = String::from_utf8_lossy(&contents);
format!("failed to parse JSON '{}' in {:?}",
text,
&args[1])
})?;
let output = &args[2];
let out_path = Path::new(output);