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

Add unknown class name to deserialization error #303

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
28 changes: 28 additions & 0 deletions src/transformer.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import SuperJSON from './index.js';

import { test, expect } from 'vitest';

test('throws an descriptive error when transforming', () => {
const instance = new SuperJSON();
class FunnyNumber {
constructor(private number: number) {}

// @ts-ignore
get theNumber() {
return this.number;
}
}
instance.registerClass(FunnyNumber);
expect(() =>
instance.deserialize({
json: instance.serialize({
number: new FunnyNumber(2137),
}).json,
meta: {
values: [['class', 'NotRegistered']],
},
})
).toThrowError(
`Trying to deserialize unknown class 'NotRegistered' - check https://github.com/blitz-js/superjson/issues/116#issuecomment-773996564`
);
});
2 changes: 1 addition & 1 deletion src/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ const classRule = compositeTransformation(

if (!clazz) {
throw new Error(
'Trying to deserialize unknown class - check https://github.com/blitz-js/superjson/issues/116#issuecomment-773996564'
`Trying to deserialize unknown class '${a[1]}' - check https://github.com/blitz-js/superjson/issues/116#issuecomment-773996564`
);
}

Expand Down
Loading