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

Fix for not showing path for error messages on windows #316

Merged
merged 2 commits into from
Sep 6, 2016
Merged

Fix for not showing path for error messages on windows #316

merged 2 commits into from
Sep 6, 2016

Conversation

mkls
Copy link
Contributor

@mkls mkls commented Aug 31, 2016

This bug has been around for a while now, there are two open PR's (#221 and #295) but no activity recently.
This is basically the solution proposed by @hgwood.
Tried to keep changes to the bare minimum.

@hgwood
Copy link

hgwood commented Aug 31, 2016

Third time's the charm!

@@ -217,7 +217,7 @@ Test.prototype._assert = function assert (ok, opts) {
if (!ok) {
var e = new Error('exception');
var err = (e.stack || '').split('\n');
var dir = path.dirname(__dirname) + '/';
var dir = path.dirname(__dirname) + path.sep;
Copy link
Collaborator

Choose a reason for hiding this comment

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

please use path.join here instead of directly referencing path.sep

Copy link

Choose a reason for hiding this comment

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

Do you mean path.join(path.dirname(__dirname), path.sep) ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, I see that path.join will always omit the trailing separator. This is fine as-is.

@ljharb
Copy link
Collaborator

ljharb commented Aug 31, 2016

Are there tests that ensure this isn't breaking anything, and tests that are currently failing on windows?

@mkls
Copy link
Contributor Author

mkls commented Aug 31, 2016

As far as I can tell there were no specific tests for this feature, but this modification does not break the current tests. (On windows one test was breaking even before this, I can try to fix that if needed).

If a well tested, multi-platform stack-trace parser is desired, then we should probably include stacktrace-parser as suggested in #295.
I feel like a larger refactor would introduce more possibilities for errors and the current minimal solution is easier to inspect and verify on code review. Basically you only have to decide if the changed regex would still work. I could not come up with cases where it would not.

I will be on vacation from tomorrow, but if you could give me some guidance which way to go about it, I will try to do what it takes next week.

@bsuh
Copy link

bsuh commented Sep 6, 2016

I'd like to see proper errors in all cases. So I modified tape to console.log a stack trace as well as __dirname.

node index.js

Stack Trace Path __dirname
*nix /Users/bsuh/tape-errors/node_modules/tape/lib/test.js /Users/bsuh/tape-errors/node_modules/tape/lib
Windows \vmware-host\Shared Folders\vagrant\tape-errors\node_modules\tape\lib\test.js \vmware-host\Shared Folders\vagrant\tape-errors\node_modules\tape\lib

browserify -d index.js | tape-run

Stack Trace Path __dirname
*nix node_modules/tape/lib/test.js /node_modules/tape/lib
Windows vmware-host/Shared Folders/vagrant/tape-errors/node_modules/tape/lib/test.js /vmware-host\Shared Folders\vagrant\tape-errors\node_modules\tape\lib

As I see it there are 3 problems

  1. proper errors with browserify is broken, because browserify insists on prefixing __dirname with '/' on all platforms and Chrome's stack traces don't contain prefix '/' in the filename.
  2. tape's regexp for getting the filename from stack trace expects filename to begin with '/' not working with Windows filename.
  3. Chrome's stack traces contain Unix style paths even on Windows, while browserify uses platform dependent paths for __dirname (while still prefixing with '/' on Windows ❗❓ ).

@ljharb
Copy link
Collaborator

ljharb commented Sep 6, 2016

@bsuh seems like a couple of those need filing upstream on browserify itself - can you file those, and link them here?

@bsuh
Copy link

bsuh commented Sep 6, 2016

@ljharb

  • Removing of'/' prefix from browserify __dirname seems like a breaking change. I think it's more practical for tape to handle it.
  • There is already a pull request to normalize __dirname/__filename to Unix style on Windows Fix some more Windows paths issues browserify/insert-module-globals#63 Not sure the likelyhood of it actually getting merged, since it's been open nearly a year.

@hgwood
Copy link

hgwood commented Sep 6, 2016

Lets be realistic. This is the third PR of this subject. The first two were never merged because one the two parties (the contributor or the maintainer) stopped answering requests/questions from the other party, after the discussion got too long (and that's OK).

The goal of this third attempt is to introduce the minimal change to fix the bug for most cases. The goal is not to fix for all cases (see #295 for that @bsuh).

Merging this PR is safe. The new regex is guaranteed to match anything the old one matched, so regressions are not possible. The worst than can happen is users that did not see any stack trace before seeing a partial stack trace. In the meantime, Windows users finally get proper stack traces on errors.

Lets get 80% of the benefits for 20% of the effort. 100% correctness can come later, one step at a time. :)

@ljharb
Copy link
Collaborator

ljharb commented Sep 6, 2016

@mkls would you mind rebasing on latest master so there's no merge commits?

I'll merge this after that.

This bug has been around for a while now.
Tried to keep changes to the bare minimum.
@ljharb ljharb merged commit d11bb14 into tape-testing:master Sep 6, 2016
ljharb added a commit that referenced this pull request Sep 30, 2016
 - [Fix] `throws`: only reassign “message” when it is not already non-enumerable (#320)
 - [Fix] show path for error messages on windows (#316)
 - [Fix] `.only` should not run multiple tests with the same name (#299, #303)
 - [Deps] update `glob`, `inherits`
 - [Dev Deps] update `concat-stream`, `tap`, `tap-parser`, `falafel`
 - [Tests] [Dev Deps] Update to latest version of devDependencies tap (v7) and tap-parser (v2) (#318)
 - [Tests] ensure the max_listeners test has passing output
 - [Docs] improvements (#298, #317)
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.

4 participants