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 messages reported by the framework code #1664

Open
Martinsos opened this issue Jan 23, 2024 · 2 comments
Open

Improve error messages reported by the framework code #1664

Martinsos opened this issue Jan 23, 2024 · 2 comments

Comments

@Martinsos
Copy link
Member

Martinsos commented Jan 23, 2024

Important

by @sodic

This issue explores improving code integration error messages (errors we get in places where framework code integrates with the user code).
The other kind of error messages the framework code might report (errors in user code detected while building the framework code) are explored in #2247.

Related:

Right now, after restructuring, there are quite some error messages that are not easy to decifer.
Not that it was perfect before, but some of them seem to have worsened (while maybe some other have improved?). Let's track some of them down here so we can look into fixing it.

If in Wasp we import JS path that doesn't exist, we get message from [ Server ] that is not very clear.
For example, for

apiNamespace fooBarNamespace {
  middlewareConfigFn: import { fooBarNamespace } from "@src/foo.js",
  path: "/foo/bar"
}

if foo.js doesn't exist, we get

[ Server ] src/routes/apis/index.ts(8,84): error TS2307: Cannot find module '../../../../../../src/foo.js' or its corresponding type declarations.

It is not clear at all from this what the cause of that error is, what is the source, where is that path wrongly used. It is not even very clear that that path is leading to this file belonging to user.

Similarly, this is what we get if foo.js exists but doesn't export { fooBarNamespace }:

[ Server ] src/routes/apis/index.ts(8,10): error TS2305: Module '"../../../../../../src/foo.js"' has no exported member 'fooBarNamespace'.
@Martinsos
Copy link
Member Author

Another one:
If in main.wasp we provide a path to server file, without .js extension, then that doesn't work, and error is something like:

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/martin/git/wasp-lang/wasp/waspc/examples/todo-typescript/.wasp/out/server/dist/src/serverSetup' imported from /home/martin/git/wasp-lang/wasp/waspc/examples/todo-typescript/.wasp/out/server/dist/.wasp/out/server/src/middleware/globalMiddleware.js
[ Server!]     at new NodeError (node:internal/errors:393:5)
[ Server!]     at finalizeResolution (node:internal/modules/esm/resolve:323:11)
[ Server!]     at moduleResolve (node:internal/modules/esm/resolve:916:10)
[ Server!]     at defaultResolve (node:internal/modules/esm/resolve:1124:11)
[ Server!]     at nextResolve (node:internal/modules/esm/loader:163:28)
[ Server!]     at ESMLoader.resolve (node:internal/modules/esm/loader:841:30)
[ Server!]     at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
[ Server!]     at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:40)
[ Server!]     at link (node:internal/modules/esm/module_job:75:36) {
[ Server!]   code: 'ERR_MODULE_NOT_FOUND'
[ Server!] }

Very hard to figure out! One solution to this might be just to allow server/ code to work without extensions in the imports, this would be the best solution, instead of fixing the actual error message.

@sodic sodic added post-0.12.0 enhancement New feature or request regression labels Mar 4, 2024
@sodic sodic changed the title Improve error messages Improve error messages reported by the framework code Mar 6, 2024
@sodic
Copy link
Contributor

sodic commented Aug 23, 2024

The extension stuff is a more general problem tracked in #2222.

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

No branches or pull requests

2 participants