Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Commit

Permalink
feat: improve JSON errors debuggability
Browse files Browse the repository at this point in the history
As seen in #393 previously
JSON decoding errors are obscure.

This changes improve the debugging in two cases:
  - The `package.json` file fails to decode; now emits a clearer error.
  - The wranglerjs backend returns an invalid JSON; now preserves the
  output file for further investigation.
    The console doesn't print the output file location by default, you
    need to pass `RUST_LOG=info` while running `wrangler build` and
    search for `--output-file=FILE` argument passed to wranglerjs.
  • Loading branch information
xtuc committed Aug 5, 2019
1 parent 1841a16 commit cd1782f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/commands/build/wranglerjs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ pub fn run_build(project: &Project) -> Result<(), failure::Error> {

if status.success() {
let output = fs::read_to_string(temp_file.clone()).expect("could not retrieve ouput");
fs::remove_file(temp_file)?;

let wranglerjs_output: WranglerjsOutput =
serde_json::from_str(&output).expect("could not parse wranglerjs output");
Expand All @@ -54,10 +53,10 @@ pub fn run_build(project: &Project) -> Result<(), failure::Error> {
wranglerjs_output.project_size()
);

fs::remove_file(temp_file)?;
message::success(&msg);
Ok(())
} else {
fs::remove_file(temp_file)?;
failure::bail!("failed to execute `{:?}`: exited with {}", command, status)
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/commands/publish/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ impl Package {
)
}

let package_json: String = fs::read_to_string(manifest_path)?.parse()?;
let package: Package = serde_json::from_str(&package_json)?;
let package_json: String = fs::read_to_string(manifest_path.clone())?.parse()?;
let package: Package = serde_json::from_str(&package_json)
.expect(&format!("could not parse {:?}", manifest_path));

Ok(package)
}
Expand Down

0 comments on commit cd1782f

Please sign in to comment.