MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / code_error

Function code_error

crates/core/src/host/v8/syscall/v2.rs:309–335  ·  view source on GitHub ↗

Construct a `SpacetimeHostError` value given an errno and message.

(
    scope: &mut PinScope<'scope, '_>,
    code: u16,
    message: Option<&str>,
)

Source from the content-addressed store, hash-verified

307
308/// Construct a `SpacetimeHostError` value given an errno and message.
309fn code_error<'scope>(
310 scope: &mut PinScope<'scope, '_>,
311 code: u16,
312 message: Option<&str>,
313) -> ExcResult<ExceptionValue<'scope>> {
314 const DEFAULT_MESSAGE: &StringConst = &StringConst::new("Unknown error");
315 let message = match message {
316 Some(msg) => msg.into_string(scope).map_err(|e| e.into_range_error().throw(scope))?,
317 None => strerror(code).unwrap_or(DEFAULT_MESSAGE).string(scope),
318 };
319 let exc = match scope
320 .get_current_context()
321 .get_embedder_data(scope, super::super::GET_ERROR_CONSTRUCTOR_SLOT)
322 {
323 // get_error_constructor: (code: number) => new (message: string) => Error
324 Some(get_error_constructor) => {
325 let errno_value = code.to_value(scope);
326 let cls = call_free_fun(scope, get_error_constructor.cast(), &[errno_value])?;
327 let cls = cast!(scope, cls, v8::Function, "function").map_err(|e| e.throw(scope))?;
328 cls.new_instance(scope, &[message.into()])
329 .ok_or_else(exception_already_thrown)?
330 .into()
331 }
332 None => v8::Exception::error(scope, message),
333 };
334 Ok(ExceptionValue(exc))
335}
336
337/// Turns a [`NodesError`] into a thrown exception.
338fn throw_nodes_error(abi_call: AbiCall, scope: &mut PinScope<'_, '_>, error: NodesError) -> ExceptionThrown {

Callers 2

handle_sys_call_errorFunction · 0.70
throw_nodes_errorFunction · 0.70

Calls 11

call_free_funFunction · 0.85
ExceptionValueClass · 0.85
into_range_errorMethod · 0.80
stringMethod · 0.80
unwrap_orMethod · 0.80
to_valueMethod · 0.80
castMethod · 0.80
newFunction · 0.50
OkFunction · 0.50
into_stringMethod · 0.45
throwMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…