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] Migration fixes #6096

Merged
merged 4 commits into from
Aug 20, 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
Next Next commit
handle error without message
dummdidumm committed Aug 19, 2022

Verified

This commit was signed with the committer’s verified signature.
wolfogre Jason Song
commit 80ab86509fb2cefd94f1846629693376b34ba75f
14 changes: 10 additions & 4 deletions packages/migrate/migrations/routes/migrate_page_js/index.js
Original file line number Diff line number Diff line change
@@ -85,10 +85,16 @@ export function migrate_page(content, filename) {
if (nodes.error) {
const message = is_string_like(nodes.error)
? nodes.error.getText()
: is_new(nodes.error, 'Error') && nodes.error.arguments[0].getText();

if (message) {
automigration(node, file.code, `throw error(${status || 500}, ${message});`);
: is_new(nodes.error, 'Error')
? /** @type {string | undefined} */ (nodes.error.arguments[0]?.getText())
: false;

if (message !== false) {
automigration(
node,
file.code,
`throw error(${status || 500}${message ? `, ${message}` : ''});`
);
imports.add('error');
return;
}
23 changes: 23 additions & 0 deletions packages/migrate/migrations/routes/migrate_page_js/samples.md
Original file line number Diff line number Diff line change
@@ -157,6 +157,29 @@ export function load({ session }) {
}
```

## Error constructor with no arguments

```js before
export function load({ session }) {
if (!session.user?.admin) {
return {
status: 403,
error: new Error()
};
}
}
```

```js after
import { error } from '@sveltejs/kit';

export function load({ session }) {
if (!session.user?.admin) {
throw error(403);
}
}
```

## Error status with no error

```js before