brumate 0.5.2 → 0.6.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/{boot-Difa0qdg.d.ts → boot-CMvhoWRu.d.ts} +2 -2
- package/dist/cli.js +2 -2
- package/dist/{client-DvsU9qxG.d.ts → client-C4kNKGwH.d.ts} +18 -5
- package/dist/{client-De-7aGlO.js → client-eVI8Wc95.js} +171 -29
- package/dist/client-eVI8Wc95.js.map +1 -0
- package/dist/{defer-DlFYiAuK.js → defer-pKO0S6UT.js} +2 -2
- package/dist/{defer-DlFYiAuK.js.map → defer-pKO0S6UT.js.map} +1 -1
- package/dist/{devtools-Di_dI9tS.js → devtools-DqqqdI4b.js} +4 -4
- package/dist/{devtools-Di_dI9tS.js.map → devtools-DqqqdI4b.js.map} +1 -1
- package/dist/{devtools-panel-BvIKX1LY.js → devtools-panel--GYjFZ35.js} +2 -2
- package/dist/{devtools-panel-BvIKX1LY.js.map → devtools-panel--GYjFZ35.js.map} +1 -1
- package/dist/{features-D5kLyihb.js → features-CbgII-o7.js} +4 -2
- package/dist/features-CbgII-o7.js.map +1 -0
- package/dist/{files-s4wmjcZV.js → files-CR-V05xd.js} +2 -2
- package/dist/{files-s4wmjcZV.js.map → files-CR-V05xd.js.map} +1 -1
- package/dist/index.d.ts +8 -4
- package/dist/index.js +2 -7
- package/dist/index.js.map +1 -1
- package/dist/{inspect-BLPt-dZZ.js → inspect-ddfGeww0.js} +236 -57
- package/dist/inspect-ddfGeww0.js.map +1 -0
- package/dist/{loader-krRrJuIv.js → loader-CQkAXO0g.js} +11 -3
- package/dist/loader-CQkAXO0g.js.map +1 -0
- package/dist/routes-D21FQyGF.js +51 -0
- package/dist/routes-D21FQyGF.js.map +1 -0
- package/dist/{rpc-BYYAj1vV.js → rpc-BgYnfg_a.js} +3 -3
- package/dist/{rpc-BYYAj1vV.js.map → rpc-BgYnfg_a.js.map} +1 -1
- package/dist/runtime/bundles.d.ts +1 -1
- package/dist/runtime/client.d.ts +2 -2
- package/dist/runtime/client.js +3 -3
- package/dist/runtime/devtools.d.ts +1 -1
- package/dist/runtime/devtools.js +1 -1
- package/dist/runtime/hot.d.ts +1 -1
- package/dist/runtime/loader.d.ts +2 -2
- package/dist/runtime/loader.js +2 -2
- package/dist/runtime/routes.js +1 -51
- package/dist/runtime/server.d.ts +2 -2
- package/dist/runtime/server.js +3 -3
- package/dist/runtime/signals.d.ts +2 -140
- package/dist/runtime/signals.js +4 -1
- package/dist/runtime/signals.js.map +1 -1
- package/dist/runtime/static-loader.d.ts +2 -2
- package/dist/runtime/static-loader.js +1 -1
- package/dist/runtime/testing.d.ts +24 -4
- package/dist/runtime/testing.js +66 -2
- package/dist/runtime/testing.js.map +1 -1
- package/dist/{produce-Cq6KKi7b.js → search-params-CM1RWR2P.js} +25 -3
- package/dist/search-params-CM1RWR2P.js.map +1 -0
- package/dist/{server-Doy5HR7r.js → server-BcT9icQ4.js} +107 -40
- package/dist/server-BcT9icQ4.js.map +1 -0
- package/dist/{server-CAwIqrXl.d.ts → server-dP_ucRiJ.d.ts} +42 -3
- package/dist/signals-BwD4u22K.d.ts +165 -0
- package/dist/{static-loader-9Nc1GvF0.d.ts → static-loader-CGthkX0s.d.ts} +2 -2
- package/dist/{static-loader-DoHWsf9t.js → static-loader-DCxASuzA.js} +3 -3
- package/dist/{static-loader-DoHWsf9t.js.map → static-loader-DCxASuzA.js.map} +1 -1
- package/dist/{stream-BdhzvPQO.js → stream-DRjx0keF.js} +2 -2
- package/dist/{stream-BdhzvPQO.js.map → stream-DRjx0keF.js.map} +1 -1
- package/dist/vite.d.ts +1 -1
- package/dist/vite.js +17 -12
- package/dist/vite.js.map +1 -1
- package/elements.d.ts +231 -35
- package/package.json +6 -1
- package/skills/brumate/references/errors.md +32 -12
- package/skills/brumate/references/signals.md +27 -25
- package/skills/brumate/references/syntax.md +1 -1
- package/dist/client-De-7aGlO.js.map +0 -1
- package/dist/features-D5kLyihb.js.map +0 -1
- package/dist/inspect-BLPt-dZZ.js.map +0 -1
- package/dist/loader-krRrJuIv.js.map +0 -1
- package/dist/produce-Cq6KKi7b.js.map +0 -1
- package/dist/runtime/routes.js.map +0 -1
- package/dist/server-Doy5HR7r.js.map +0 -1
|
@@ -2,13 +2,22 @@ import { n as closesParagraph, r as firstTag } from "./nesting-DA5vJw9X.js";
|
|
|
2
2
|
import { n as MODIFIERS } from "./events-LgLdp1R7.js";
|
|
3
3
|
import { C as spread$1, S as rawHTML, a as attribute$1, b as ownValue, d as escapeAttribute, f as handlerEntry, g as isRaw, n as VOID_ELEMENTS, p as insertValue, r as actionAttributes, s as bindEntry, u as escape, v as onAttribute, w as styleElement } from "./html-t1JpkODI.js";
|
|
4
4
|
import { n as deleteCookie, o as setCookie, r as getCookies } from "./cookies-Cnbf4w-S.js";
|
|
5
|
-
import { a as plugins, c as functionReferences, i as callPlugins, o as serialOptions, r as toChunkStream, s as syncPlugins, t as STREAM_TYPE } from "./stream-
|
|
6
|
-
import {
|
|
5
|
+
import { a as plugins, c as functionReferences, i as callPlugins, o as serialOptions, r as toChunkStream, s as syncPlugins, t as STREAM_TYPE } from "./stream-DRjx0keF.js";
|
|
6
|
+
import { C as parseId, _ as isBinding, a as Binding, c as ElementReference, d as PARTS, f as PropPromise, g as isAsyncIterable, h as addEntryHandlers, l as FunctionReference, m as SlotReference, o as CHILDREN_REF, s as ChildrenReference, u as MemoError, y as isSlotReference } from "./search-params-CM1RWR2P.js";
|
|
7
7
|
import { n as serverSecrets } from "./secrets-BxagsJxJ.js";
|
|
8
8
|
import "./context-CTiSzQRc.js";
|
|
9
9
|
import { a as applyIntent, d as formatPath, f as getAt, m as groupIssues, r as INTENT, u as formValues, v as parseIntent, y as parsePath } from "./forms-nXK7-Lv_.js";
|
|
10
10
|
import { crossSerialize, crossSerializeStream, fromJSON, toJSON } from "seroval";
|
|
11
11
|
//#region src/runtime/request.ts
|
|
12
|
+
/** Where the server takes the error of a `waitUntil` promise that no host keeps, in place of the log. */
|
|
13
|
+
const failures = {};
|
|
14
|
+
/** The sink of a handler, or none without one. */
|
|
15
|
+
function errorSink(handler) {
|
|
16
|
+
return handler && {
|
|
17
|
+
handler,
|
|
18
|
+
handled: /* @__PURE__ */ new WeakSet()
|
|
19
|
+
};
|
|
20
|
+
}
|
|
12
21
|
function noTrace() {}
|
|
13
22
|
/** Ends an entry of the trace when a value settles, if it is a promise, or at once. */
|
|
14
23
|
function traceValue(value, end) {
|
|
@@ -119,6 +128,8 @@ var RequestEvent = class {
|
|
|
119
128
|
* `fetch(url, { signal })`, so work that nobody waits for stops.
|
|
120
129
|
*/
|
|
121
130
|
signal = this.controller.signal;
|
|
131
|
+
/** Where the errors of the request go, when the app has an `onError`. */
|
|
132
|
+
errors;
|
|
122
133
|
keepGoing;
|
|
123
134
|
constructor(request, options = {}) {
|
|
124
135
|
this.request = request;
|
|
@@ -126,6 +137,7 @@ var RequestEvent = class {
|
|
|
126
137
|
this.keepGoing = options.waitUntil;
|
|
127
138
|
this.address = options.address;
|
|
128
139
|
this.prerender = options.prerender ?? false;
|
|
140
|
+
this.errors = errorSink(options.onError);
|
|
129
141
|
watchPersonal(request.headers, () => {
|
|
130
142
|
this.personal = true;
|
|
131
143
|
});
|
|
@@ -145,7 +157,7 @@ var RequestEvent = class {
|
|
|
145
157
|
*/
|
|
146
158
|
waitUntil(promise) {
|
|
147
159
|
if (this.keepGoing) this.keepGoing(promise);
|
|
148
|
-
else promise.catch((error) => console.error(error));
|
|
160
|
+
else promise.catch((error) => (failures.report ?? console.error)(error, this));
|
|
149
161
|
}
|
|
150
162
|
/**
|
|
151
163
|
* Sets the status of the page response, such as 404 for a page that shows
|
|
@@ -1369,8 +1381,18 @@ var Context = class Context {
|
|
|
1369
1381
|
params = {};
|
|
1370
1382
|
/** The request of the page, when it renders with one. */
|
|
1371
1383
|
event;
|
|
1384
|
+
/** The sink of the event, or of the `onError` option of a render without a request. */
|
|
1385
|
+
errors;
|
|
1372
1386
|
/** Results of server function calls in this render, so the same call runs once. */
|
|
1373
1387
|
calls = /* @__PURE__ */ new Map();
|
|
1388
|
+
/** The event of the request, or undefined when the render has none. */
|
|
1389
|
+
requestEvent() {
|
|
1390
|
+
return this.root.event;
|
|
1391
|
+
}
|
|
1392
|
+
/** Where the errors of the render go, when the app has an `onError`. */
|
|
1393
|
+
errorSink() {
|
|
1394
|
+
return this.root.errors;
|
|
1395
|
+
}
|
|
1374
1396
|
/** The event of the page, for `getEvent()` in a component, which the compiler rewrites to this. */
|
|
1375
1397
|
getEvent() {
|
|
1376
1398
|
const event = this.root.event;
|
|
@@ -2152,7 +2174,7 @@ function stateValue(node) {
|
|
|
2152
2174
|
function heldError(error, ctx) {
|
|
2153
2175
|
let sent;
|
|
2154
2176
|
if (ctx?.isDev()) sent = error instanceof Error ? error : new Error(String(error));
|
|
2155
|
-
else sent = safeError(error, "The page could not compute a value");
|
|
2177
|
+
else sent = safeError(error, "The page could not compute a value", ctx);
|
|
2156
2178
|
return Object.assign(new MemoError(sent), { [Symbol.for("brumate.held")]: true });
|
|
2157
2179
|
}
|
|
2158
2180
|
/**
|
|
@@ -2804,9 +2826,11 @@ async function render(Root, props, options = {}) {
|
|
|
2804
2826
|
kind: options.defer ? "defer" : "page",
|
|
2805
2827
|
waitUntil: options.waitUntil,
|
|
2806
2828
|
address: options.address,
|
|
2807
|
-
prerender: options.prerender
|
|
2829
|
+
prerender: options.prerender,
|
|
2830
|
+
onError: options.onError
|
|
2808
2831
|
}) : void 0);
|
|
2809
2832
|
ctx.event = event;
|
|
2833
|
+
ctx.errors = event ? event.errors : errorSink(options.onError);
|
|
2810
2834
|
const rendered = await ctx.run(() => Root(props, ctx));
|
|
2811
2835
|
ctx.send();
|
|
2812
2836
|
const html = beforeBodyEnd(rendered, ctx.portals.join(""));
|
|
@@ -2860,7 +2884,7 @@ async function render(Root, props, options = {}) {
|
|
|
2860
2884
|
}));
|
|
2861
2885
|
}, onError, finish, void 0, last);
|
|
2862
2886
|
}
|
|
2863
|
-
async function renderCatch(boundary, error) {
|
|
2887
|
+
async function renderCatch(boundary, error, kind) {
|
|
2864
2888
|
const entry = boundary.catchers.at(-1);
|
|
2865
2889
|
if (!entry) return;
|
|
2866
2890
|
const child = new Context(ctx, void 0, 0, `${boundary.id}c.`);
|
|
@@ -2872,7 +2896,7 @@ async function render(Root, props, options = {}) {
|
|
|
2872
2896
|
key: entry.key
|
|
2873
2897
|
};
|
|
2874
2898
|
} catch (failure) {
|
|
2875
|
-
|
|
2899
|
+
logError(failure, kind, ctx.errorSink(), event);
|
|
2876
2900
|
return;
|
|
2877
2901
|
}
|
|
2878
2902
|
}
|
|
@@ -2921,15 +2945,15 @@ async function render(Root, props, options = {}) {
|
|
|
2921
2945
|
});
|
|
2922
2946
|
}, (error) => {
|
|
2923
2947
|
if (boundary.cancelled || boundary.around || stopped()) {
|
|
2924
|
-
|
|
2948
|
+
logError(error, "stream", ctx.errorSink(), event);
|
|
2925
2949
|
turn(skip);
|
|
2926
2950
|
return;
|
|
2927
2951
|
}
|
|
2928
2952
|
turn((after) => {
|
|
2929
|
-
if (ctx.isDev())
|
|
2930
|
-
renderCatch(boundary, error).then((result) => {
|
|
2953
|
+
if (ctx.isDev()) logError(error, "stream", ctx.errorSink(), event);
|
|
2954
|
+
renderCatch(boundary, error, "stream").then((result) => {
|
|
2931
2955
|
if (!result) {
|
|
2932
|
-
pending().push(failScript(caught(error, ctx), refs, boundary.id, root, nonce));
|
|
2956
|
+
pending().push(failScript(caught(error, ctx, "stream"), refs, boundary.id, root, nonce));
|
|
2933
2957
|
skip(after);
|
|
2934
2958
|
return;
|
|
2935
2959
|
}
|
|
@@ -2975,10 +2999,10 @@ async function render(Root, props, options = {}) {
|
|
|
2975
2999
|
result = await boundary.render;
|
|
2976
3000
|
} catch (error) {
|
|
2977
3001
|
if (boundary.cancelled || boundary.around) continue;
|
|
2978
|
-
if (ctx.isDev())
|
|
2979
|
-
const replacement = await renderCatch(boundary, error);
|
|
3002
|
+
if (ctx.isDev()) logError(error, "page", ctx.errorSink(), event);
|
|
3003
|
+
const replacement = await renderCatch(boundary, error, "page");
|
|
2980
3004
|
if (!replacement) {
|
|
2981
|
-
|
|
3005
|
+
logError(error, "page", ctx.errorSink(), event);
|
|
2982
3006
|
continue;
|
|
2983
3007
|
}
|
|
2984
3008
|
catches.push([replacement.key, replacement.html]);
|
|
@@ -3185,17 +3209,48 @@ async function writeParts(parts, options, controller, cancelled = () => false) {
|
|
|
3185
3209
|
* The message and status that answer an error. A `ServerError` sends its
|
|
3186
3210
|
* own. Any other error is logged, and sends `fallback` with status 500.
|
|
3187
3211
|
*/
|
|
3188
|
-
function errorAnswer(error, fallback) {
|
|
3212
|
+
function errorAnswer(error, fallback, kind, event) {
|
|
3189
3213
|
if (error instanceof ServerError) return {
|
|
3190
3214
|
message: error.message,
|
|
3191
3215
|
status: error.status
|
|
3192
3216
|
};
|
|
3193
|
-
|
|
3217
|
+
logError(error, kind, event?.errors, event);
|
|
3194
3218
|
return {
|
|
3195
3219
|
message: fallback,
|
|
3196
3220
|
status: 500
|
|
3197
3221
|
};
|
|
3198
3222
|
}
|
|
3223
|
+
failures.report = (error, event) => logError(error, event.kind, event.errors, event);
|
|
3224
|
+
/**
|
|
3225
|
+
* Logs an error of the server, or gives it to `onError` when the app has one, which then logs
|
|
3226
|
+
* what it wants. A `ServerError` is an answer, so the handler does not get it. A handler that
|
|
3227
|
+
* fails has its error logged with the first one.
|
|
3228
|
+
*/
|
|
3229
|
+
function logError(error, kind, sink, event) {
|
|
3230
|
+
if (!sink) {
|
|
3231
|
+
console.error(error);
|
|
3232
|
+
return;
|
|
3233
|
+
}
|
|
3234
|
+
if (error instanceof ServerError) return;
|
|
3235
|
+
if (typeof error === "object" && error !== null) {
|
|
3236
|
+
if (sink.handled.has(error)) return;
|
|
3237
|
+
sink.handled.add(error);
|
|
3238
|
+
}
|
|
3239
|
+
if (kind === "stream" && event?.kind === "defer") kind = "defer";
|
|
3240
|
+
function fail(failure) {
|
|
3241
|
+
console.error(failure);
|
|
3242
|
+
console.error(error);
|
|
3243
|
+
}
|
|
3244
|
+
try {
|
|
3245
|
+
const result = sink.handler(error, {
|
|
3246
|
+
event,
|
|
3247
|
+
kind
|
|
3248
|
+
});
|
|
3249
|
+
if (isThenable(result)) Promise.resolve(result).catch(fail);
|
|
3250
|
+
} catch (failure) {
|
|
3251
|
+
fail(failure);
|
|
3252
|
+
}
|
|
3253
|
+
}
|
|
3199
3254
|
/** Errors that `safeError` logged, so a failure read in two places logs once. */
|
|
3200
3255
|
const logged = /* @__PURE__ */ new WeakSet();
|
|
3201
3256
|
/**
|
|
@@ -3203,13 +3258,15 @@ const logged = /* @__PURE__ */ new WeakSet();
|
|
|
3203
3258
|
* `ServerError`, or `fallback`, and no stack, which holds paths of the server. Any other error is
|
|
3204
3259
|
* logged once. A thrown value that is not an object is logged each time.
|
|
3205
3260
|
*/
|
|
3206
|
-
function safeError(error, fallback) {
|
|
3261
|
+
function safeError(error, fallback, ctx, kind) {
|
|
3207
3262
|
let message = fallback;
|
|
3263
|
+
const event = ctx?.requestEvent();
|
|
3264
|
+
const sink = ctx?.errorSink();
|
|
3208
3265
|
if (error instanceof ServerError) message = error.message;
|
|
3209
|
-
else if (typeof error !== "object" || error === null)
|
|
3266
|
+
else if (typeof error !== "object" || error === null || sink) logError(error, kind ?? event?.kind ?? "page", sink, event);
|
|
3210
3267
|
else if (!logged.has(error)) {
|
|
3211
3268
|
logged.add(error);
|
|
3212
|
-
|
|
3269
|
+
logError(error, kind ?? event?.kind ?? "page", sink, event);
|
|
3213
3270
|
}
|
|
3214
3271
|
const safe = new Error(message);
|
|
3215
3272
|
safe.stack = "";
|
|
@@ -3222,9 +3279,9 @@ function safeError(error, fallback) {
|
|
|
3222
3279
|
* logged, as for a server function that fails. The body renders with this value too, so the
|
|
3223
3280
|
* HTML cannot print what the state does not carry.
|
|
3224
3281
|
*/
|
|
3225
|
-
function caught(error, ctx) {
|
|
3282
|
+
function caught(error, ctx, kind) {
|
|
3226
3283
|
if (ctx.isDev()) return error;
|
|
3227
|
-
return safeError(error, "The page could not render this part");
|
|
3284
|
+
return safeError(error, "The page could not render this part", ctx, kind);
|
|
3228
3285
|
}
|
|
3229
3286
|
/** True for a request that a `<form>` sent, without client code. */
|
|
3230
3287
|
function isFormPost(request) {
|
|
@@ -3293,15 +3350,15 @@ function skewAnswer(build) {
|
|
|
3293
3350
|
* response has `headers`. With `base`, the location of a redirect is
|
|
3294
3351
|
* resolved against it.
|
|
3295
3352
|
*/
|
|
3296
|
-
async function callWithForm(invoke, headers, base) {
|
|
3353
|
+
async function callWithForm(invoke, headers, event, base) {
|
|
3297
3354
|
try {
|
|
3298
3355
|
return { result: await invoke() };
|
|
3299
3356
|
} catch (error) {
|
|
3300
|
-
return { answer: formFailure(error, headers, base) };
|
|
3357
|
+
return { answer: formFailure(error, headers, event, base) };
|
|
3301
3358
|
}
|
|
3302
3359
|
}
|
|
3303
3360
|
/** The answer to a form post whose server function threw, or whose data could not be read. */
|
|
3304
|
-
function formFailure(error, headers, base) {
|
|
3361
|
+
function formFailure(error, headers, event, base) {
|
|
3305
3362
|
if (error instanceof Redirect) {
|
|
3306
3363
|
headers.set("location", base ? new URL(error.location, base).href : error.location);
|
|
3307
3364
|
return respond(null, {
|
|
@@ -3309,7 +3366,7 @@ function formFailure(error, headers, base) {
|
|
|
3309
3366
|
headers
|
|
3310
3367
|
});
|
|
3311
3368
|
}
|
|
3312
|
-
const { message, status } = errorAnswer(error, "The server function failed");
|
|
3369
|
+
const { message, status } = errorAnswer(error, "The server function failed", "call", event);
|
|
3313
3370
|
headers.set("content-type", "text/plain; charset=utf-8");
|
|
3314
3371
|
return respond(message, {
|
|
3315
3372
|
status,
|
|
@@ -3323,7 +3380,7 @@ function formFailure(error, headers, base) {
|
|
|
3323
3380
|
*/
|
|
3324
3381
|
async function handleForm(invoke, event) {
|
|
3325
3382
|
const { headers } = event;
|
|
3326
|
-
const outcome = await callWithForm(invoke, headers);
|
|
3383
|
+
const outcome = await callWithForm(invoke, headers, event);
|
|
3327
3384
|
if ("answer" in outcome) return outcome.answer;
|
|
3328
3385
|
headers.set("location", event.request.headers.get("referer") ?? "/");
|
|
3329
3386
|
return respond(null, {
|
|
@@ -3405,13 +3462,14 @@ async function handleRequest(functions, request, prefix = "/_brumate", options =
|
|
|
3405
3462
|
kind: "call",
|
|
3406
3463
|
waitUntil: options.waitUntil,
|
|
3407
3464
|
address: options.address,
|
|
3408
|
-
prerender: options.prerender
|
|
3465
|
+
prerender: options.prerender,
|
|
3466
|
+
onError: options.onError
|
|
3409
3467
|
});
|
|
3410
3468
|
let args;
|
|
3411
3469
|
try {
|
|
3412
3470
|
args = form ? [await request.formData()] : await readArgs(request);
|
|
3413
3471
|
} catch (error) {
|
|
3414
|
-
return posted ? formFailure(error, event.headers) : callFailure(error, event.headers);
|
|
3472
|
+
return posted ? formFailure(error, event.headers, event) : callFailure(error, event.headers, event);
|
|
3415
3473
|
}
|
|
3416
3474
|
event.call = {
|
|
3417
3475
|
id,
|
|
@@ -3441,11 +3499,11 @@ async function answerCall(functions, event, run) {
|
|
|
3441
3499
|
headers.set("content-type", STREAM_TYPE);
|
|
3442
3500
|
return respond(toChunkStream(result, (reason) => event.abort(reason)), { headers });
|
|
3443
3501
|
} catch (error) {
|
|
3444
|
-
return callFailure(error, headers);
|
|
3502
|
+
return callFailure(error, headers, event);
|
|
3445
3503
|
}
|
|
3446
3504
|
}
|
|
3447
3505
|
/** The answer to a call whose server function threw, or whose arguments could not be read. */
|
|
3448
|
-
function callFailure(error, headers) {
|
|
3506
|
+
function callFailure(error, headers, event) {
|
|
3449
3507
|
if (error instanceof Redirect) {
|
|
3450
3508
|
headers.set("x-brumate-redirect", error.location);
|
|
3451
3509
|
return respond(null, {
|
|
@@ -3453,7 +3511,7 @@ function callFailure(error, headers) {
|
|
|
3453
3511
|
headers
|
|
3454
3512
|
});
|
|
3455
3513
|
}
|
|
3456
|
-
const { message, status } = errorAnswer(error, "The server function failed");
|
|
3514
|
+
const { message, status } = errorAnswer(error, "The server function failed", "call", event);
|
|
3457
3515
|
headers.set("content-type", "application/json");
|
|
3458
3516
|
return respond(JSON.stringify({ error: message }), {
|
|
3459
3517
|
status,
|
|
@@ -3584,7 +3642,7 @@ function viewComponent(view, props) {
|
|
|
3584
3642
|
async function runAction(fn, event) {
|
|
3585
3643
|
const { request } = event;
|
|
3586
3644
|
const args = event.call.args;
|
|
3587
|
-
const outcome = await callWithForm(() => withEvent(event, () => fn(...args)), new Headers(), request.url);
|
|
3645
|
+
const outcome = await callWithForm(() => withEvent(event, () => fn(...args)), new Headers(), event, request.url);
|
|
3588
3646
|
return "answer" in outcome ? outcome : { actions: /* @__PURE__ */ new Map([[fn, outcome.result]]) };
|
|
3589
3647
|
}
|
|
3590
3648
|
/**
|
|
@@ -3605,7 +3663,7 @@ async function readAction(url, event, options) {
|
|
|
3605
3663
|
args: [await request.formData()]
|
|
3606
3664
|
};
|
|
3607
3665
|
} catch (error) {
|
|
3608
|
-
return formFailure(error, new Headers(), request.url);
|
|
3666
|
+
return formFailure(error, new Headers(), event, request.url);
|
|
3609
3667
|
}
|
|
3610
3668
|
}
|
|
3611
3669
|
/** Renders the page of a route tree, streamed, with the results of a form for `$action`. */
|
|
@@ -3749,7 +3807,7 @@ async function renderError(views, error, params, request, options) {
|
|
|
3749
3807
|
error
|
|
3750
3808
|
}, request, options, { status: error.status });
|
|
3751
3809
|
} catch (failure) {
|
|
3752
|
-
|
|
3810
|
+
logError(failure, options.event?.kind ?? "page", options.event?.errors, options.event);
|
|
3753
3811
|
}
|
|
3754
3812
|
}
|
|
3755
3813
|
/** Runs the middleware of the folders on the path, from the outside in, around the answer. */
|
|
@@ -3781,7 +3839,8 @@ async function handleRoute(tree, request, options = {}) {
|
|
|
3781
3839
|
kind: await requestKind(request, match),
|
|
3782
3840
|
waitUntil: options.waitUntil,
|
|
3783
3841
|
address: options.address,
|
|
3784
|
-
prerender: options.prerender
|
|
3842
|
+
prerender: options.prerender,
|
|
3843
|
+
onError: options.onError
|
|
3785
3844
|
});
|
|
3786
3845
|
event.route = match?.route;
|
|
3787
3846
|
const answer = await routeAnswer(tree, match, url, {
|
|
@@ -3835,7 +3894,7 @@ function fillHoles(tree, request, shell, options) {
|
|
|
3835
3894
|
});
|
|
3836
3895
|
return answer?.ok && answer.headers.get("x-brumate-defer") === boundary ? await answer.text() : "";
|
|
3837
3896
|
} catch (error) {
|
|
3838
|
-
|
|
3897
|
+
logError(error, "defer", options.event?.errors ?? errorSink(options.onError), options.event);
|
|
3839
3898
|
return "";
|
|
3840
3899
|
}
|
|
3841
3900
|
}
|
|
@@ -3891,7 +3950,12 @@ async function answerRoute(match, request, url, options) {
|
|
|
3891
3950
|
if (match.endpoint) {
|
|
3892
3951
|
const endpoint = await match.endpoint();
|
|
3893
3952
|
const handler = endpoint[request.method] ?? (request.method === "HEAD" ? endpoint.GET : void 0);
|
|
3894
|
-
if (handler)
|
|
3953
|
+
if (handler) try {
|
|
3954
|
+
return await withEvent(options.event, () => handler(request, match.params));
|
|
3955
|
+
} catch (error) {
|
|
3956
|
+
if (!isRedirect(error) && options.event?.errors) logError(error, "endpoint", options.event.errors, options.event);
|
|
3957
|
+
throw error;
|
|
3958
|
+
}
|
|
3895
3959
|
if (match.view.load === missingPage || request.method !== "GET") {
|
|
3896
3960
|
const allow = [];
|
|
3897
3961
|
for (const name of Object.keys(endpoint)) if (/^[A-Z]+$/.test(name)) allow.push(name);
|
|
@@ -3928,8 +3992,11 @@ async function renderRoute(match, request, url, options) {
|
|
|
3928
3992
|
status: error.status,
|
|
3929
3993
|
headers: { location: new URL(error.location, url).href }
|
|
3930
3994
|
});
|
|
3931
|
-
if (options.dev && !(error instanceof ServerError))
|
|
3932
|
-
|
|
3995
|
+
if (options.dev && !(error instanceof ServerError)) {
|
|
3996
|
+
logError(error, options.event?.kind ?? "page", options.event?.errors, options.event);
|
|
3997
|
+
throw error;
|
|
3998
|
+
}
|
|
3999
|
+
const page = await renderError(match.errors, errorAnswer(error, "Something went wrong", options.event?.kind ?? "page", options.event), match.params, request, options);
|
|
3933
4000
|
if (page) return page;
|
|
3934
4001
|
throw error;
|
|
3935
4002
|
}
|
|
@@ -3975,4 +4042,4 @@ function spread(attributes, on, names) {
|
|
|
3975
4042
|
//#endregion
|
|
3976
4043
|
export { dedupe as $, streamParts as A, ValidationError as B, setClientBundles as C, start as D, spread as E, RateLimitError as F, matchRoute as G, parse as H, clientAddress as I, revalidate as J, cached as K, configureRateLimit as L, wait as M, waitAll as N, stateScript as O, idempotent as P, ServerError as Q, rateLimit as R, renderToStream as S, spacerTag as T, parseForm as U, fieldErrors as V, safeParse as W, storageStore as X, setCacheStore as Y, RequestEvent as Z, memo as _, attribute as a, ready as b, children as c, handleRequest as d, defineMiddleware as et, handleRoute as f, lazy as g, isCrossSite as h, actionResult as i, withEvent as it, streamState as j, stateValue as k, component as l, insert as m, NotReady as n, isRedirect as nt, binding as o, inlineBodies as p, memoryStore as q, action as r, redirect as rt, caught as s, Context as t, getEvent as tt, dynamic as u, packState as v, settled as w, render as x, read as y, parseSubmission as z };
|
|
3977
4044
|
|
|
3978
|
-
//# sourceMappingURL=server-
|
|
4045
|
+
//# sourceMappingURL=server-BcT9icQ4.js.map
|