Skip to content

Commit dfce084

Browse files
simongdaviesCopilot
andcommitted
Update src/js-host-api/src/lib.rs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent f1214c9 commit dfce084

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

src/js-host-api/src/lib.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -229,18 +229,16 @@ const MAX_MODULE_IDENTIFIER_LEN: usize = 256;
229229
/// surface them properly. The inner layer's validation still runs as a
230230
/// safety net, but would produce generic `ERR_INTERNAL` codes.
231231
fn validate_napi_module_identifier(value: &str, label: &str) -> napi::Result<()> {
232-
// Delegate core validation (empty, colons) to the shared implementation.
233-
// Map through invalid_arg_error to preserve ERR_INVALID_ARG codes —
234-
// Check length first to short-circuit expensive validation on
235-
// accidentally large strings (DoS / multi-MB input guard).
232+
// First enforce a hard length limit to short‑circuit expensive validation on
233+
// accidentally large strings (DoS / multi‑MB input guard). Then delegate core
234+
// validation (e.g., emptiness, colons) to the shared implementation, mapping
235+
// its errors through invalid_arg_error so callers consistently receive
236+
// ERR_INVALID_ARG rather than generic ERR_INTERNAL codes.
236237
if value.len() > MAX_MODULE_IDENTIFIER_LEN {
237238
return Err(invalid_arg_error(&format!(
238239
"{label} must not exceed {MAX_MODULE_IDENTIFIER_LEN} bytes"
239240
)));
240241
}
241-
// Delegate core validation (empty, colons) to the shared implementation.
242-
// Map through invalid_arg_error to preserve ERR_INVALID_ARG codes —
243-
// to_napi_error would produce ERR_INTERNAL for these validation errors.
244242
hyperlight_js::validate_module_identifier(value, label)
245243
.map_err(|e| invalid_arg_error(&e.to_string()))?;
246244
if value.chars().any(|c| c.is_control()) {

0 commit comments

Comments
 (0)