Skip to content

Commit 9d71548

Browse files
committed
Error if no describe_module
1 parent d311665 commit 9d71548

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

crates/core/src/host/v8/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -659,9 +659,8 @@ fn extract_description<'scope>(
659659
|a, b, c| log_traceback(replica_ctx, a, b, c),
660660
|| {
661661
catch_exception(scope, |scope| {
662-
let Some(describe_module) = get_hook(scope, ModuleHookKey::DescribeModule) else {
663-
return Ok(RawModuleDef::V9(Default::default()));
664-
};
662+
let describe_module = get_hook(scope, ModuleHookKey::DescribeModule)
663+
.context("The `spacetimedb/server` package was never imported into the module")?;
665664
let def = call_describe_module(scope, describe_module)?;
666665
Ok(def)
667666
})
@@ -675,14 +674,15 @@ fn extract_description<'scope>(
675674
mod test {
676675
use super::to_value::test::with_scope;
677676
use super::*;
677+
use crate::host::v8::error::{ErrorOrException, ExceptionThrown};
678678
use crate::host::wasm_common::module_host_actor::ReducerOp;
679679
use crate::host::ArgsTuple;
680680
use spacetimedb_lib::{ConnectionId, Identity};
681681
use spacetimedb_primitives::ReducerId;
682682

683683
fn with_module_catch<T>(
684684
code: &str,
685-
logic: impl for<'scope> FnOnce(&mut PinScope<'scope, '_>) -> ExcResult<T>,
685+
logic: impl for<'scope> FnOnce(&mut PinScope<'scope, '_>) -> Result<T, ErrorOrException<ExceptionThrown>>,
686686
) -> anyhow::Result<T> {
687687
with_scope(|scope| {
688688
eval_user_module_catch(scope, code).unwrap();
@@ -708,7 +708,7 @@ mod test {
708708
timestamp: Timestamp::from_micros_since_unix_epoch(24),
709709
args: &ArgsTuple::nullary(),
710710
};
711-
call_call_reducer(scope, fun, op)
711+
Ok(call_call_reducer(scope, fun, op)?)
712712
})
713713
};
714714

crates/core/src/host/v8/syscall/mod.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
use spacetimedb_lib::RawModuleDef;
2-
use spacetimedb_lib::VersionTuple;
1+
use spacetimedb_lib::{RawModuleDef, VersionTuple};
32
use v8::{callback_scope, Context, FixedArray, Local, Module, PinScope};
43

54
use crate::host::v8::de::scratch_buf;
6-
use crate::host::v8::error::ExcResult;
7-
use crate::host::v8::error::Throwable;
8-
use crate::host::v8::error::TypeError;
5+
use crate::host::v8::error::{ErrorOrException, ExcResult, ExceptionThrown, Throwable, TypeError};
96
use crate::host::wasm_common::abi::parse_abi_version;
107
use crate::host::wasm_common::module_host_actor::{ReducerOp, ReducerResult};
118

@@ -85,7 +82,7 @@ pub(super) fn call_call_reducer(
8582
pub(super) fn call_describe_module<'scope>(
8683
scope: &mut PinScope<'scope, '_>,
8784
fun: HookFunction<'_>,
88-
) -> ExcResult<RawModuleDef> {
85+
) -> Result<RawModuleDef, ErrorOrException<ExceptionThrown>> {
8986
let HookFunction(ver, fun) = fun;
9087
match ver {
9188
AbiVersion::V1 => v1::call_describe_module(scope, fun),

crates/core/src/host/v8/syscall/v1.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::database_logger::{LogLevel, Record};
44
use crate::error::NodesError;
55
use crate::host::instance_env::InstanceEnv;
66
use crate::host::v8::de::{deserialize_js, scratch_buf};
7-
use crate::host::v8::error::{ExcResult, ExceptionThrown, TypeError};
7+
use crate::host::v8::error::{ErrorOrException, ExcResult, ExceptionThrown};
88
use crate::host::v8::from_value::cast;
99
use crate::host::v8::ser::serialize_to_js;
1010
use crate::host::v8::string::{str_from_ident, StringConst};
@@ -16,6 +16,7 @@ use crate::host::wasm_common::instrumentation::span;
1616
use crate::host::wasm_common::module_host_actor::{ReducerOp, ReducerResult};
1717
use crate::host::wasm_common::{err_to_errno_and_log, RowIterIdx, TimingSpan, TimingSpanIdx};
1818
use crate::host::AbiCall;
19+
use anyhow::Context;
1920
use spacetimedb_lib::{bsatn, ConnectionId, Identity, RawModuleDef};
2021
use spacetimedb_primitives::{errno, ColId, IndexId, ReducerId, TableId};
2122
use spacetimedb_sats::Serialize;
@@ -363,7 +364,10 @@ pub(super) fn call_call_reducer(
363364
}
364365

365366
/// Calls the registered `__describe_module__` function hook.
366-
pub(super) fn call_describe_module(scope: &mut PinScope<'_, '_>, fun: Local<'_, Function>) -> ExcResult<RawModuleDef> {
367+
pub(super) fn call_describe_module(
368+
scope: &mut PinScope<'_, '_>,
369+
fun: Local<'_, Function>,
370+
) -> Result<RawModuleDef, ErrorOrException<ExceptionThrown>> {
367371
// Call the function.
368372
let raw_mod_js = call_free_fun(scope, fun, &[])?;
369373

@@ -377,8 +381,7 @@ pub(super) fn call_describe_module(scope: &mut PinScope<'_, '_>, fun: Local<'_,
377381
.map_err(|e| e.throw(scope))?;
378382

379383
let bytes = raw_mod.get_contents(&mut []);
380-
let module =
381-
bsatn::from_slice::<RawModuleDef>(bytes).map_err(|_e| TypeError("invalid bsatn module def").throw(scope))?;
384+
let module = bsatn::from_slice::<RawModuleDef>(bytes).context("invalid bsatn module def")?;
382385
Ok(module)
383386
}
384387

0 commit comments

Comments
 (0)