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 #123

Merged
merged 2 commits into from
Feb 22, 2020
Merged

Conversation

codebling
Copy link
Contributor

A typical error message (e.g. Browserify) with this module looks like the following:

Error: Cannot find module './nonexistant' from '/code/project/test'
    at /code/project/node_modules/resolve/lib/async.js:46:17
    at process (/code/project/node_modules/resolve/lib/async.js:173:43)
    at ondir (/code/project/node_modules/resolve/lib/async.js:188:17)
    at load (/code/project/node_modules/resolve/lib/async.js:69:43)
    at onex (/code/project/node_modules/resolve/lib/async.js:92:31)
    at /code/project/node_modules/resolve/lib/async.js:22:47
    at FSReqWrap.oncomplete (fs.js:123:15)

This has several issues. First, it does not show the file from which the missing module is being required (it does show the name of the missing file/module and the directory from which it is searching). Second, the stack trace doesn't provide a good indication of the source of the modules involved. Users with monolithic build tasks will find this error extremely confusing, as it does not provide a clear indication of what action could have generated this error, why it was generated, where it was generated or how to fix it.

This PR changes the error such that it appears like so:

Error: Can't walk dependency graph: Cannot find module './nonexistant' from '/code/project/test'
    required by /code/project/test/deep4.js
    at /code/project/node_modules/module-deps/index.js:362:19
    at onresolve (/code/project/node_modules/module-deps/index.js:174:25)
    at /code/project/node_modules/browserify/index.js:490:22
    at /code/project/node_modules/browser-resolve/index.js:265:24
    at /code/project/node_modules/resolve/lib/async.js:55:18
    at load (/code/project/node_modules/resolve/lib/async.js:69:43)
    at onex (/code/project/node_modules/resolve/lib/async.js:92:31)
    at /code/project/node_modules/resolve/lib/async.js:22:47
    at FSReqWrap.oncomplete (fs.js:123:15)

This error:

  • shows the requiring file
  • has a stack trace that presents a better indication of the origin of the error (Browserify is listed directly, along with several other involved modules)

Ideally, this error would give the entire traceback (in the form of required by ) from the unresolved module ./nonexistant all the way back up the require chain to the entry file, but that is a non-trivial change.

60/60 tests passing.

@codebling
Copy link
Contributor Author

3 year bump.

Copy link
Member

@goto-bus-stop goto-bus-stop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

coming up on 4 years 😬

I like the error message, but I don't think throwing away the original stack trace is better. If the error indicates 'not found' it makes sense, but if there is a bug in the resolve implementation that causes a TypeError for example, having that context is important.

In modern Node.js versions, the 'error' event propagates the stack trace, so we get both the trace from this PR and the trace from the original error. With the below change, the final result is:

Error: Can't walk dependency graph: Cannot find module 'x' from '~/Code/browserify/module-deps'
    required by ~/Code/browserify/module-deps/t.js
    at ~/Code/browserify/module-deps/node_modules/browser-resolve/node_modules/resolve/lib/async.js:46:17
    at process (~/Code/browserify/module-deps/node_modules/browser-resolve/node_modules/resolve/lib/async.js:173:43)
    at ondir (~/Code/browserify/module-deps/node_modules/browser-resolve/node_modules/resolve/lib/async.js:188:17)
    at load (~/Code/browserify/module-deps/node_modules/browser-resolve/node_modules/resolve/lib/async.js:69:43)
    at onex (~/Code/browserify/module-deps/node_modules/browser-resolve/node_modules/resolve/lib/async.js:92:31)
    at ~/Code/browserify/module-deps/node_modules/browser-resolve/node_modules/resolve/lib/async.js:22:47
    at FSReqCallback.oncomplete (fs.js:170:21)
Emitted 'error' event on Deps instance at:
    at ~/Code/browserify/module-deps/index.js:383:25
    at onresolve (~/Code/browserify/module-deps/index.js:181:25)
    at ~/Code/browserify/module-deps/node_modules/browser-resolve/index.js:265:24
    at ~/Code/browserify/module-deps/node_modules/browser-resolve/node_modules/resolve/lib/async.js:46:14
    at process (~/Code/browserify/module-deps/node_modules/browser-resolve/node_modules/resolve/lib/async.js:173:43)
    [... lines matching original stack trace ...]
    at FSReqCallback.oncomplete (fs.js:170:21)

what do you think about that?

index.js Outdated Show resolved Hide resolved
@codebling
Copy link
Contributor Author

Hey @goto-bus-stop!

Looking at the problem again, I'm not sure it would have made sense to change only this error's stack and let all of the other possible error paths continue to show the original stack. That's without considering what you mentioned about newer versions of Node. With an event trace like you showed, there is absolutely no reason to replace the stack.

Thanks for looking at this! I appreciate the solo mission that you've undertaken to maintain this project and sort through the backlog of issues and PRs. I appreciate this because I believe in open source, and I'd would very much like for this project to continue to be maintained and supported to benefit those who still use it. I, however, no longer do. Seeing as this PR and Browserify#1663 both went unacknowleged, and noticing the downward trend in commits in the project, I eventually switched to the excellent Parcel.js. Best of luck!

@goto-bus-stop goto-bus-stop merged commit f10b9d8 into browserify:master Feb 22, 2020
@goto-bus-stop
Copy link
Member

applied my suggestion to this branch & merged—thanks for the PR!

@codebling
Copy link
Contributor Author

Thanks for the merge!

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

Successfully merging this pull request may close these issues.

2 participants