Commit 3de47145 authored by Jörg Thalheim's avatar Jörg Thalheim
Browse files

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
parent 1318ddf6
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -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);