@objectstack/runtime 11.7.0 → 11.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1947,7 +1947,16 @@ declare class QuickJSScriptRunner implements ScriptRunner {
1947
1947
  private installCtx;
1948
1948
  }
1949
1949
  declare class SandboxError extends Error {
1950
- constructor(message: string);
1950
+ /**
1951
+ * For errors thrown by *user* script/hook/action code: the original business
1952
+ * message without the `<kind> '<name>' threw:` debug wrapper that lives in
1953
+ * `.message`. Safe to surface to end users (e.g. an action's error toast);
1954
+ * the wrapped `.message` stays for server logs. Undefined for the sandbox's
1955
+ * own internal errors (capability denials, timeouts, marshalling failures),
1956
+ * which have no user-meaningful inner message.
1957
+ */
1958
+ readonly innerMessage?: string;
1959
+ constructor(message: string, innerMessage?: string);
1951
1960
  }
1952
1961
 
1953
1962
  /**
package/dist/index.d.ts CHANGED
@@ -1947,7 +1947,16 @@ declare class QuickJSScriptRunner implements ScriptRunner {
1947
1947
  private installCtx;
1948
1948
  }
1949
1949
  declare class SandboxError extends Error {
1950
- constructor(message: string);
1950
+ /**
1951
+ * For errors thrown by *user* script/hook/action code: the original business
1952
+ * message without the `<kind> '<name>' threw:` debug wrapper that lives in
1953
+ * `.message`. Safe to surface to end users (e.g. an action's error toast);
1954
+ * the wrapped `.message` stays for server logs. Undefined for the sandbox's
1955
+ * own internal errors (capability denials, timeouts, marshalling failures),
1956
+ * which have no user-meaningful inner message.
1957
+ */
1958
+ readonly innerMessage?: string;
1959
+ constructor(message: string, innerMessage?: string);
1951
1960
  }
1952
1961
 
1953
1962
  /**
package/dist/index.js CHANGED
@@ -311,6 +311,9 @@ function formatErr(err) {
311
311
  }
312
312
  return String(err);
313
313
  }
314
+ function userFacingMessage(raw) {
315
+ return raw.startsWith("Error: ") ? raw.slice("Error: ".length) : raw;
316
+ }
314
317
  var DEFAULT_HOOK_TIMEOUT_MS, DEFAULT_ACTION_TIMEOUT_MS, DEFAULT_MEMORY_MB, QuickJSScriptRunner, SandboxError;
315
318
  var init_quickjs_runner = __esm({
316
319
  "src/sandbox/quickjs-runner.ts"() {
@@ -375,7 +378,10 @@ var init_quickjs_runner = __esm({
375
378
  if (result.error) {
376
379
  const err = vm.dump(result.error);
377
380
  result.error.dispose();
378
- throw new SandboxError(`${args.origin.kind} '${args.origin.name}' threw: ${formatErr(err)}`);
381
+ throw new SandboxError(
382
+ `${args.origin.kind} '${args.origin.name}' threw: ${formatErr(err)}`,
383
+ userFacingMessage(formatErr(err))
384
+ );
379
385
  }
380
386
  result.value.dispose();
381
387
  const resH = vm.getProp(vm.global, "__result");
@@ -397,7 +403,10 @@ var init_quickjs_runner = __esm({
397
403
  if (evalRes.error) {
398
404
  const err = vm.dump(evalRes.error);
399
405
  evalRes.error.dispose();
400
- throw new SandboxError(`${args.origin.kind} '${args.origin.name}' threw: ${formatErr(err)}`);
406
+ throw new SandboxError(
407
+ `${args.origin.kind} '${args.origin.name}' threw: ${formatErr(err)}`,
408
+ userFacingMessage(formatErr(err))
409
+ );
401
410
  }
402
411
  evalRes.value.dispose();
403
412
  let pumps = 0;
@@ -407,13 +416,19 @@ var init_quickjs_runner = __esm({
407
416
  if (pending.error) {
408
417
  const err = vm.dump(pending.error);
409
418
  pending.error.dispose();
410
- throw new SandboxError(`${args.origin.kind} '${args.origin.name}' threw: ${formatErr(err)}`);
419
+ throw new SandboxError(
420
+ `${args.origin.kind} '${args.origin.name}' threw: ${formatErr(err)}`,
421
+ userFacingMessage(formatErr(err))
422
+ );
411
423
  }
412
424
  const errH = vm.getProp(vm.global, "__error");
413
425
  const errStr = vm.dump(errH);
414
426
  errH.dispose();
415
427
  if (errStr) {
416
- throw new SandboxError(`${args.origin.kind} '${args.origin.name}' threw: ${errStr}`);
428
+ throw new SandboxError(
429
+ `${args.origin.kind} '${args.origin.name}' threw: ${errStr}`,
430
+ userFacingMessage(String(errStr))
431
+ );
417
432
  }
418
433
  const resH = vm.getProp(vm.global, "__result");
419
434
  const resStr = vm.dump(resH);
@@ -606,9 +621,10 @@ var init_quickjs_runner = __esm({
606
621
  }
607
622
  };
608
623
  SandboxError = class extends Error {
609
- constructor(message) {
624
+ constructor(message, innerMessage) {
610
625
  super(message);
611
626
  this.name = "SandboxError";
627
+ this.innerMessage = innerMessage;
612
628
  }
613
629
  };
614
630
  }
@@ -4495,8 +4511,11 @@ var _HttpDispatcher = class _HttpDispatcher {
4495
4511
  }
4496
4512
  return { handled: true, response: this.success({ success: true, data: result }) };
4497
4513
  } catch (err) {
4498
- const msg = err?.message ?? String(err);
4499
- return { handled: true, response: this.success({ success: false, error: msg }) };
4514
+ const full = err?.message ?? String(err);
4515
+ const inner = err?.innerMessage;
4516
+ const clientMsg = typeof inner === "string" && inner ? inner : full;
4517
+ if (clientMsg !== full) console.error(`[action ${objectName}/${actionName}] ${full}`);
4518
+ return { handled: true, response: this.success({ success: false, error: clientMsg }) };
4500
4519
  }
4501
4520
  }
4502
4521
  /**