Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] show more descriptive error if data returned from load is a non-POJO #7386

Merged
merged 3 commits into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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/shiny-eels-brush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

Show more descriptive error if data returned from `load` is a non-POJO
14 changes: 14 additions & 0 deletions packages/kit/src/runtime/server/page/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,20 @@ export async function render_response({
`Data returned from \`load\` while rendering ${event.routeId} is not serializable: ${error.message} (data.${match[2]})`
);
}

const nonPojoError = /pojo/i.exec(error.message);

if (nonPojoError) {
const constructorName = branch.find(({ server_data }) => server_data?.data?.constructor?.name)
?.server_data?.data?.constructor?.name;

throw new Error(
`Data returned from \`load\` (while rendering ${event.routeId}) must be a plain object${
constructorName ? ` rather than an instance of ${constructorName}` : ''
}`
);
}

throw error;
}

Expand Down