fix: don't store codeframe on error object (#1898)
This commit is contained in:
@@ -792,6 +792,7 @@ export class ServerContext {
|
|||||||
// deno-lint-ignore no-explicit-any
|
// deno-lint-ignore no-explicit-any
|
||||||
ctx?: any,
|
ctx?: any,
|
||||||
error?: unknown,
|
error?: unknown,
|
||||||
|
codeFrame?: string,
|
||||||
) => {
|
) => {
|
||||||
return async (data?: Data, options?: RenderOptions) => {
|
return async (data?: Data, options?: RenderOptions) => {
|
||||||
if (route.component === undefined) {
|
if (route.component === undefined) {
|
||||||
@@ -819,6 +820,7 @@ export class ServerContext {
|
|||||||
data,
|
data,
|
||||||
state: ctx?.state,
|
state: ctx?.state,
|
||||||
error,
|
error,
|
||||||
|
codeFrame,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (resp instanceof Response) {
|
if (resp instanceof Response) {
|
||||||
@@ -905,14 +907,13 @@ export class ServerContext {
|
|||||||
"%cAn error occurred during route handling or page rendering.",
|
"%cAn error occurred during route handling or page rendering.",
|
||||||
"color:red",
|
"color:red",
|
||||||
);
|
);
|
||||||
|
let codeFrame: string | undefined;
|
||||||
if (this.#dev && error instanceof Error) {
|
if (this.#dev && error instanceof Error) {
|
||||||
const codeFrame = await getCodeFrame(error);
|
codeFrame = await getCodeFrame(error);
|
||||||
|
|
||||||
if (codeFrame) {
|
if (codeFrame) {
|
||||||
console.error();
|
console.error();
|
||||||
console.error(codeFrame);
|
console.error(codeFrame);
|
||||||
// deno-lint-ignore no-explicit-any
|
|
||||||
(error as any).codeFrame = codeFrame;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.error(error);
|
console.error(error);
|
||||||
@@ -922,7 +923,7 @@ export class ServerContext {
|
|||||||
{
|
{
|
||||||
...ctx,
|
...ctx,
|
||||||
error,
|
error,
|
||||||
render: errorHandlerRender(req, {}, ctx, error),
|
render: errorHandlerRender(req, {}, ctx, error, codeFrame),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -90,8 +90,7 @@ export default function DefaultErrorPage(
|
|||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
if (error instanceof Error) {
|
if (error instanceof Error) {
|
||||||
title = error.message;
|
title = error.message;
|
||||||
// deno-lint-ignore no-explicit-any
|
codeFrame = props.codeFrame;
|
||||||
codeFrame = (error as any).codeFrame;
|
|
||||||
stack = error.stack ?? "";
|
stack = error.stack ?? "";
|
||||||
} else {
|
} else {
|
||||||
title = String(error);
|
title = String(error);
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ export interface RenderOptions<Data> {
|
|||||||
data?: Data;
|
data?: Data;
|
||||||
state?: Record<string, unknown>;
|
state?: Record<string, unknown>;
|
||||||
error?: unknown;
|
error?: unknown;
|
||||||
|
codeFrame?: string;
|
||||||
lang?: string;
|
lang?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,6 +154,9 @@ export async function render<Data>(
|
|||||||
if (opts.error) {
|
if (opts.error) {
|
||||||
props.error = opts.error;
|
props.error = opts.error;
|
||||||
}
|
}
|
||||||
|
if (opts.codeFrame) {
|
||||||
|
props.codeFrame = opts.codeFrame;
|
||||||
|
}
|
||||||
|
|
||||||
const csp: ContentSecurityPolicy | undefined = opts.route.csp
|
const csp: ContentSecurityPolicy | undefined = opts.route.csp
|
||||||
? defaultCsp()
|
? defaultCsp()
|
||||||
|
|||||||
@@ -418,6 +418,9 @@ export interface ErrorPageProps {
|
|||||||
|
|
||||||
/** The error that caused the error page to be loaded. */
|
/** The error that caused the error page to be loaded. */
|
||||||
error: unknown;
|
error: unknown;
|
||||||
|
|
||||||
|
/** Sringified code frame (only in development mode) */
|
||||||
|
codeFrame?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ErrorHandlerContext<State = Record<string, unknown>>
|
export interface ErrorHandlerContext<State = Record<string, unknown>>
|
||||||
|
|||||||
Reference in New Issue
Block a user