chore: surface import map JSON parse error to user (#11573)

This commit is contained in:
David Sherret 2021-08-03 15:29:12 -04:00 committed by GitHub
parent 86f89f9222
commit 1cd95dd8b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 5 deletions

View File

@ -65,10 +65,11 @@ impl ImportMap {
) -> Result<Self, ImportMapError> {
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(

View File

@ -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 })