Construct a `SpacetimeHostError` value given an errno and message.
(
scope: &mut PinScope<'scope, '_>,
code: u16,
message: Option<&str>,
)
| 307 | |
| 308 | /// Construct a `SpacetimeHostError` value given an errno and message. |
| 309 | fn 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. |
| 338 | fn throw_nodes_error(abi_call: AbiCall, scope: &mut PinScope<'_, '_>, error: NodesError) -> ExceptionThrown { |
no test coverage detected
searching dependent graphs…