Skip to content

Commit

Permalink
move error from client to shared
Browse files Browse the repository at this point in the history
  • Loading branch information
Ocean-OS committed Dec 24, 2024
1 parent 2e656d3 commit b08a4b4
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 26 deletions.
6 changes: 0 additions & 6 deletions documentation/docs/98-reference/.generated/client-errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,3 @@ Reading state that was created inside the same derived is forbidden. Consider us
```
Updating state inside a derived or a template expression is forbidden. If the value should not be reactive, declare it without `$state`
```

### structured_clone_state_proxy

```
To correctly clone a `$state` proxy, use `$state.snapshot` instead of `structuredClone`
```
6 changes: 6 additions & 0 deletions documentation/docs/98-reference/.generated/shared-errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ Certain lifecycle methods can only be used during component initialisation. To f
`%name%` is not a store with a `subscribe` method
```

### structured_clone_state_proxy

```
To correctly clone a `$state` proxy, use `$state.snapshot` instead of `structuredClone`
```

### svelte_element_invalid_this_value

```
Expand Down
4 changes: 0 additions & 4 deletions packages/svelte/messages/client-errors/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,3 @@ See the [migration guide](/docs/svelte/v5-migration-guide#Components-are-no-long
## state_unsafe_mutation

> Updating state inside a derived or a template expression is forbidden. If the value should not be reactive, declare it without `$state`
## structured_clone_state_proxy

> To correctly clone a `$state` proxy, use `$state.snapshot` instead of `structuredClone`
4 changes: 4 additions & 0 deletions packages/svelte/messages/shared-errors/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ Certain lifecycle methods can only be used during component initialisation. To f

> `%name%` is not a store with a `subscribe` method
## structured_clone_state_proxy

> To correctly clone a `$state` proxy, use `$state.snapshot` instead of `structuredClone`
## svelte_element_invalid_this_value

> The `this` prop on `<svelte:element>` must be a string, if defined
15 changes: 0 additions & 15 deletions packages/svelte/src/internal/client/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,19 +335,4 @@ export function state_unsafe_mutation() {
} else {
throw new Error(`https://svelte.dev/e/state_unsafe_mutation`);
}
}

/**
* To correctly clone a `$state` proxy, use `$state.snapshot` instead of `structuredClone`
* @returns {never}
*/
export function structured_clone_state_proxy() {
if (DEV) {
const error = new Error(`structured_clone_state_proxy\nTo correctly clone a \`$state\` proxy, use \`$state.snapshot\` instead of \`structuredClone\`\nhttps://svelte.dev/e/structured_clone_state_proxy`);

error.name = 'Svelte error';
throw error;
} else {
throw new Error(`https://svelte.dev/e/structured_clone_state_proxy`);
}
}
2 changes: 1 addition & 1 deletion packages/svelte/src/internal/shared/clone.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { DEV } from 'esm-env';
import { STATE_SYMBOL } from '../client/constants.js';
import * as w from './warnings.js';
import * as e from '../client/errors.js';
import * as e from './errors.js';
import {
get_prototype_of,
is_array,
Expand Down
15 changes: 15 additions & 0 deletions packages/svelte/src/internal/shared/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,19 @@ export function svelte_element_invalid_this_value() {
} else {
throw new Error(`https://svelte.dev/e/svelte_element_invalid_this_value`);
}
}

/**
* To correctly clone a `$state` proxy, use `$state.snapshot` instead of `structuredClone`
* @returns {never}
*/
export function structured_clone_state_proxy() {
if (DEV) {
const error = new Error(`structured_clone_state_proxy\nTo correctly clone a \`$state\` proxy, use \`$state.snapshot\` instead of \`structuredClone\`\nhttps://svelte.dev/e/structured_clone_state_proxy`);

error.name = 'Svelte error';
throw error;
} else {
throw new Error(`https://svelte.dev/e/structured_clone_state_proxy`);
}
}

0 comments on commit b08a4b4

Please sign in to comment.