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
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
13 changes: 13 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,19 @@ 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[0]?.server_data?.data?.constructor?.name;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be from server_data deeper in the load tree, so I think it should be

Suggested change
const constructorName = branch[0]?.server_data?.data?.constructor?.name;
const constructorName = branch.find(({ server_data }) => server_data?.data?.constructor?.name)?.server_data.data.constructor.name;


throw new Error(
`Data returned from \`load\` must be a plain object${
constructorName ? ` rather than ${constructorName} constructor` : ''
}`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

);
}

throw error;
}

Expand Down