refactor(rust): avoid panics where possible

This commit is contained in:
Amaan Qureshi 2025-09-22 21:06:50 -04:00 committed by Amaan Qureshi
parent 47c9256976
commit b0cdab85fe
2 changed files with 5 additions and 2 deletions

View file

@ -505,7 +505,6 @@ fn load_js_grammar_file(grammar_path: &Path, js_runtime: Option<&str>) -> JSResu
.wait_with_output()
.map_err(|e| JSError::IO(format!("Failed to read output from `{js_runtime}` -- {e}")))?;
match output.status.code() {
None => panic!("`{js_runtime}` process was killed"),
Some(0) => {
let stdout = String::from_utf8(output.stdout).map_err(|e| JSError::JSRuntimeUtf8 {
runtime: js_runtime.to_string(),
@ -533,6 +532,10 @@ fn load_js_grammar_file(grammar_path: &Path, js_runtime: Option<&str>) -> JSResu
runtime: js_runtime.to_string(),
code,
}),
None => Err(JSError::JSRuntimeExit {
runtime: js_runtime.to_string(),
code: -1,
}),
}
}

View file

@ -351,7 +351,7 @@ impl From<ffi::TSQuantifier> for CaptureQuantifier {
ffi::TSQuantifierZeroOrMore => Self::ZeroOrMore,
ffi::TSQuantifierOne => Self::One,
ffi::TSQuantifierOneOrMore => Self::OneOrMore,
_ => panic!("Unrecognized quantifier: {value}"),
_ => unreachable!(),
}
}
}