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 three 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.
  - The preview service returns invalid JSON; now emits a clearer error
    and full output can be seen using `RUST_LOG=info`
  • Loading branch information
xtuc committed Aug 5, 2019
1 parent 1841a16 commit 9cadf4c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 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
6 changes: 5 additions & 1 deletion src/commands/publish/preview/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ pub fn preview(
.send()?
.error_for_status();

let p: Preview = serde_json::from_str(&res?.text()?)?;
let text = &res?.text()?;
log::info!("Response from preview: {:?}", text);

let p: Preview =
serde_json::from_str(text).expect("could not create a script on cloudflareworkers.com");

let session = Uuid::new_v4().to_simple();

Expand Down

0 comments on commit 9cadf4c

Please sign in to comment.