Skip to content

Commit b0cdab8

Browse files
committed
refactor(rust): avoid panics where possible
1 parent 47c9256 commit b0cdab8

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

crates/generate/src/generate.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,6 @@ fn load_js_grammar_file(grammar_path: &Path, js_runtime: Option<&str>) -> JSResu
505505
.wait_with_output()
506506
.map_err(|e| JSError::IO(format!("Failed to read output from `{js_runtime}` -- {e}")))?;
507507
match output.status.code() {
508-
None => panic!("`{js_runtime}` process was killed"),
509508
Some(0) => {
510509
let stdout = String::from_utf8(output.stdout).map_err(|e| JSError::JSRuntimeUtf8 {
511510
runtime: js_runtime.to_string(),
@@ -533,6 +532,10 @@ fn load_js_grammar_file(grammar_path: &Path, js_runtime: Option<&str>) -> JSResu
533532
runtime: js_runtime.to_string(),
534533
code,
535534
}),
535+
None => Err(JSError::JSRuntimeExit {
536+
runtime: js_runtime.to_string(),
537+
code: -1,
538+
}),
536539
}
537540
}
538541

lib/binding_rust/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ impl From<ffi::TSQuantifier> for CaptureQuantifier {
351351
ffi::TSQuantifierZeroOrMore => Self::ZeroOrMore,
352352
ffi::TSQuantifierOne => Self::One,
353353
ffi::TSQuantifierOneOrMore => Self::OneOrMore,
354-
_ => panic!("Unrecognized quantifier: {value}"),
354+
_ => unreachable!(),
355355
}
356356
}
357357
}

0 commit comments

Comments
 (0)