mirror of
https://github.com/denoland/deno.git
synced 2025-01-12 00:54:02 -05:00
chore: surface import map JSON parse error to user (#11573)
This commit is contained in:
parent
86f89f9222
commit
1cd95dd8b5
2 changed files with 14 additions and 5 deletions
|
@ -65,10 +65,11 @@ impl ImportMap {
|
||||||
) -> Result<Self, ImportMapError> {
|
) -> Result<Self, ImportMapError> {
|
||||||
let v: Value = match serde_json::from_str(json_string) {
|
let v: Value = match serde_json::from_str(json_string) {
|
||||||
Ok(v) => v,
|
Ok(v) => v,
|
||||||
Err(_) => {
|
Err(err) => {
|
||||||
return Err(ImportMapError::Other(
|
return Err(ImportMapError::Other(format!(
|
||||||
"Unable to parse import map JSON".to_string(),
|
"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());
|
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
|
// invalid schema: 'imports' is non-object
|
||||||
for non_object in non_object_strings.to_vec() {
|
for non_object in non_object_strings.to_vec() {
|
||||||
assert!(ImportMap::from_json(
|
assert!(ImportMap::from_json(
|
||||||
|
|
|
@ -228,7 +228,7 @@ fn op_isatty(
|
||||||
{
|
{
|
||||||
use winapi::um::consoleapi;
|
use winapi::um::consoleapi;
|
||||||
|
|
||||||
let handle = get_windows_handle(&std_file)?;
|
let handle = get_windows_handle(std_file)?;
|
||||||
let mut test_mode: DWORD = 0;
|
let mut test_mode: DWORD = 0;
|
||||||
// If I cannot get mode out of console, it is not a console.
|
// If I cannot get mode out of console, it is not a console.
|
||||||
Ok(unsafe { consoleapi::GetConsoleMode(handle, &mut test_mode) != 0 })
|
Ok(unsafe { consoleapi::GetConsoleMode(handle, &mut test_mode) != 0 })
|
||||||
|
|
Loading…
Reference in a new issue