From 1cd95dd8b5046484ea79b1849e420d1c085d1e5b Mon Sep 17 00:00:00 2001 From: David Sherret Date: Tue, 3 Aug 2021 15:29:12 -0400 Subject: [PATCH] chore: surface import map JSON parse error to user (#11573) --- cli/import_map.rs | 17 +++++++++++++---- runtime/ops/tty.rs | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/cli/import_map.rs b/cli/import_map.rs index 17ac3727eb..aa76d8d769 100644 --- a/cli/import_map.rs +++ b/cli/import_map.rs @@ -65,10 +65,11 @@ impl ImportMap { ) -> Result { let v: Value = match serde_json::from_str(json_string) { Ok(v) => v, - Err(_) => { - return Err(ImportMapError::Other( - "Unable to parse import map JSON".to_string(), - )); + Err(err) => { + return Err(ImportMapError::Other(format!( + "Unable to parse import map JSON: {}", + err.to_string() + ))); } }; @@ -742,6 +743,14 @@ mod tests { assert!(ImportMap::from_json(base_url, non_object).is_err()); } + // invalid JSON message test + assert_eq!( + ImportMap::from_json(base_url, "{\"a\":1,}") + .unwrap_err() + .to_string(), + "Unable to parse import map JSON: trailing comma at line 1 column 8", + ); + // invalid schema: 'imports' is non-object for non_object in non_object_strings.to_vec() { assert!(ImportMap::from_json( diff --git a/runtime/ops/tty.rs b/runtime/ops/tty.rs index bc45c93755..e9e2e67008 100644 --- a/runtime/ops/tty.rs +++ b/runtime/ops/tty.rs @@ -228,7 +228,7 @@ fn op_isatty( { use winapi::um::consoleapi; - let handle = get_windows_handle(&std_file)?; + let handle = get_windows_handle(std_file)?; let mut test_mode: DWORD = 0; // If I cannot get mode out of console, it is not a console. Ok(unsafe { consoleapi::GetConsoleMode(handle, &mut test_mode) != 0 })