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

Improve error message "No valid runtime type for x given." #508

Open
marcj opened this issue Nov 16, 2023 · 2 comments
Open

Improve error message "No valid runtime type for x given." #508

marcj opened this issue Nov 16, 2023 · 2 comments

Comments

@marcj
Copy link
Member

marcj commented Nov 16, 2023

throw new Error(`No valid runtime type for ${stringifyValueWithType(object)} given. Is @deepkit/type-compiler correctly installed? Execute deepkit-type-install to check`);

@SamJakob had a great idea about improving this error message. Quote from discord:

Totally - I love the way Flutter does it’s error messages, they basically explain the issue in a fair bit of detail and then provide tips on how to fix it.

So for example you could have a helper function that detects if reflection is set in tsconfig.json and explains to the user that it’s not set and what it needs to be set for (in a fairly general way in case it’s a peer dependency in another framework like yours or mine) and that the user has to set it.

And then similarly for detecting if the typescript copy is patched

it's not always possible to detect tsconfig.json options or paths (since they might be provided by a build tool, or when run in the browser), but we could describe in a general way what needs to be enabled. And if the code runs in the server maybe try to check if there is a tsconfig.json and just read that file (works for beginners well enough that have likely a single tsconfig.json)

@SamJakob
Copy link
Contributor

SamJakob commented Nov 16, 2023

Also, when reflection is not set to true in tsconfig.json, the following error is returned (in this case when testing with valuesOf):

deepkit-framework/packages/type/src/reflection/reflection.ts:136
    throw new Error('No type given');
          ^
Error: No type given
    at typeOf (deepkit-framework/packages/type/src/reflection/reflection.ts:136:11)
    at valuesOf (deepkit-framework/packages/type/src/reflection/reflection.ts:98:18)
    at Object.<anonymous> (deepkit-test/src/main.ts:41:21)
    at Module._compile (node:internal/modules/cjs/loader:1233:14)
    at Module.m._compile (deepkit-test/node_modules/ts-node/src/index.ts:1618:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1287:10)
    at Object.require.extensions.<computed> [as .ts] (deepkit-test/node_modules/ts-node/src/index.ts:1621:12)
    at Module.load (node:internal/modules/cjs/loader:1091:32)
    at Function.Module._load (node:internal/modules/cjs/loader:938:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12)

Edit: this might be specific to valuesOf (and/or typeOf) in any case

@marcj
Copy link
Member Author

marcj commented Nov 16, 2023

good catch. we should make sure we don't have several different error messages meaning the same thing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants