Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/serious-llamas-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

[fix] more informative serialization error messages
6 changes: 5 additions & 1 deletion packages/kit/src/runtime/server/page/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,5 +248,9 @@ function check_serializability(value, id, path) {
}
}

throw new Error(`${path} returned from action in ${id} cannot be serialized as JSON`);
throw new Error(
`${path} returned from action in ${id} cannot be serialized as JSON without loosing its original type` +
Comment thread
Rich-Harris marked this conversation as resolved.
Outdated
// probably the most common case, so let's give a hint
(value instanceof Date ? ' (Date objects are serialized to strings)' : '')
Comment thread
Rich-Harris marked this conversation as resolved.
Outdated
);
}
5 changes: 4 additions & 1 deletion packages/kit/src/runtime/server/page/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,10 @@ export async function render_response({
// function, but it would mean passing more stuff around than we currently do
const error = /** @type {any} */ (e);
const match = /\[(\d+)\]\.data\.(.+)/.exec(error.path);
if (match) throw new Error(`${error.message} (data.${match[2]})`);
if (match)
throw new Error(
`Returned data from a load function related to routeId ${event.routeId} is not serializable: ${error.message} (data.${match[2]})`
);
throw error;
}

Expand Down