make errors better

elliott/hydratable
Elliott Johnson 12 hours ago
parent 74b878f198
commit 98849452b3

@ -41,6 +41,17 @@ This error occurs when using `hydratable` multiple times with the same key. To a
</script>
```
### hydratable_serialization_failed
```
Failed to serialize `hydratable` data.
`hydratable` can serialize anything [`uneval` from `devalue`](https://npmjs.com/package/uneval) can, plus Promises.
Stack:
%stack%
```
### lifecycle_function_unavailable
```

@ -33,6 +33,15 @@ This error occurs when using `hydratable` multiple times with the same key. To a
</script>
```
## hydratable_serialization_failed
> Failed to serialize `hydratable` data.
>
> `hydratable` can serialize anything [`uneval` from `devalue`](https://npmjs.com/package/uneval) can, plus Promises.
>
> Stack:
> %stack%
## lifecycle_function_unavailable
> `%name%(...)` is not available on the server

@ -53,6 +53,29 @@ ${stack2}\nhttps://svelte.dev/e/hydratable_clobbering`);
throw error;
}
/**
* Failed to serialize `hydratable` data.
*
* `hydratable` can serialize anything [`uneval` from `devalue`](https://npmjs.com/package/uneval) can, plus Promises.
*
* Stack:
* %stack%
* @param {string} stack
* @returns {never}
*/
export function hydratable_serialization_failed(stack) {
const error = new Error(`hydratable_serialization_failed\nFailed to serialize \`hydratable\` data.
\`hydratable\` can serialize anything [\`uneval\` from \`devalue\`](https://npmjs.com/package/uneval) can, plus Promises.
Stack:
${stack}\nhttps://svelte.dev/e/hydratable_serialization_failed`);
error.name = 'Svelte error';
throw error;
}
/**
* `%name%(...)` is not available on the server
* @param {string} name

@ -66,7 +66,12 @@ function encode(key, value, values, unresolved) {
needs_thunk = false;
return result;
};
const serialize_promise = value.then(scoped_uneval);
const serialize_promise = value
.then(scoped_uneval)
.catch((devalue_error) =>
e.hydratable_serialization_failed(serialization_stack(entry.stack, devalue_error?.stack))
);
serialize_promise.catch(() => {});
unresolved?.set(serialize_promise, key);
serialize_promise.finally(() => unresolved?.delete(serialize_promise));
@ -123,3 +128,18 @@ async function compare(key, a, b) {
);
}
}
/**
* @param {string | undefined} root_stack
* @param {string | undefined} uneval_stack
*/
function serialization_stack(root_stack, uneval_stack) {
let out = '';
if (root_stack) {
out += root_stack + '\n';
}
if (uneval_stack) {
out += 'Caused by:\n' + uneval_stack + '\n';
}
return out || '<missing stack trace>';
}

Loading…
Cancel
Save