diff options
author | 2024-08-13 15:47:12 +0100 | |
---|---|---|
committer | 2024-08-13 10:47:12 -0400 | |
commit | c7bda4cd672864babc3cebd19a2dd2e1af85c087 (patch) | |
tree | 43c7e8d76ac6d238cfcfedca3526aff0c79ee029 /packages | |
parent | 315ec07e1b25042cf0298b0d55dbcd6dd6a39890 (diff) | |
download | astro-c7bda4cd672864babc3cebd19a2dd2e1af85c087.tar.gz astro-c7bda4cd672864babc3cebd19a2dd2e1af85c087.tar.zst astro-c7bda4cd672864babc3cebd19a2dd2e1af85c087.zip |
fix(actions): save error stack trace in memory (#11689)
Diffstat (limited to 'packages')
-rw-r--r-- | packages/astro/src/actions/runtime/virtual/shared.ts | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/packages/astro/src/actions/runtime/virtual/shared.ts b/packages/astro/src/actions/runtime/virtual/shared.ts index 57dc40449..00233bf41 100644 --- a/packages/astro/src/actions/runtime/virtual/shared.ts +++ b/packages/astro/src/actions/runtime/virtual/shared.ts @@ -213,14 +213,16 @@ export type SerializedActionResult = export function serializeActionResult(res: SafeResult<any, any>): SerializedActionResult { if (res.error) { + if (import.meta.env?.DEV) { + actionResultErrorStack.set(res.error.stack) + } return { type: 'error', status: res.error.status, contentType: 'application/json', body: JSON.stringify({ ...res.error, - message: res.error.message, - stack: import.meta.env.PROD ? undefined : res.error.stack, + message: res.error.message }), }; } @@ -243,7 +245,15 @@ export function serializeActionResult(res: SafeResult<any, any>): SerializedActi export function deserializeActionResult(res: SerializedActionResult): SafeResult<any, any> { if (res.type === 'error') { - return { error: ActionError.fromJson(JSON.parse(res.body)), data: undefined }; + if (import.meta.env?.PROD) { + return { error: ActionError.fromJson(JSON.parse(res.body)), data: undefined }; + } else { + const error = ActionError.fromJson(JSON.parse(res.body)); + error.stack = actionResultErrorStack.get(); + return { + error, data: undefined + } + } } if (res.type === 'empty') { return { data: undefined, error: undefined }; @@ -255,3 +265,16 @@ export function deserializeActionResult(res: SerializedActionResult): SafeResult error: undefined, }; } + +// in-memory singleton to save the stack trace +const actionResultErrorStack = function actionResultErrorStackFn() { + let errorStack: string | undefined; + return { + set(stack: string | undefined) { + errorStack = stack; + }, + get() { + return errorStack; + } + } +}(); |