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

Use stack-utils for nicer stack traces. #418

Merged
merged 1 commit into from
Jan 14, 2016

Conversation

jamestalmage
Copy link
Contributor

I have extracted node-taps stack cleaning algorithm into it's own module, tapjs/stack-utils.

It creates much nicer stack traces than beautify-stack.js does. There is a bit of work left to do in the stack-utils module, but once these are done, this should be mergeable:

Screenshots below.

@jamestalmage
Copy link
Contributor Author

Before:

screenshot 2016-01-13 12 19 18

After:

screenshot 2016-01-13 13 21 22

@jamestalmage
Copy link
Contributor Author

Before:

screenshot 2016-01-13 12 20 27

After:

screenshot 2016-01-13 13 16 38

@jamestalmage
Copy link
Contributor Author

Before:

screenshot 2016-01-13 13 09 57

After:

screenshot 2016-01-13 13 12 13

@vadimdemedes
Copy link
Contributor

Love love love this!

@@ -118,6 +118,7 @@
"serialize-error": "^1.1.0",
"set-immediate-shim": "^1.0.1",
"source-map-support": "^0.4.0",
"stack-utils": "github:tapjs/stack-utils#long-stack-traces",
Copy link
Contributor

Choose a reason for hiding this comment

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

No need for github: prefix, it will work the same without it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just did

npm i -S tapjs/stack-utils#long-stack-traces

and that is how it modified package.json. I want to get that PR merged before we merge this anyways.

Copy link
Member

Choose a reason for hiding this comment

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

npm apparently adds this now, but it's not needed as github is the default for shorthands.

@jamestalmage
Copy link
Contributor Author

Love love love this!

😄

If you could review the issues and PR's on stack-utils that would be a big help.


var Promise = require('bluebird');

test(() => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops. This fixture isn't used anywhere. I just used it to create some of the above screenshots. It should be deleted.

@jamestalmage
Copy link
Contributor Author

I'm also wondering if we should do something like this:

var opts = {};

// If debug is enabled, don't delete stack trace lines.
if (!debug('ava').enabled) {
  opt.internals = StackUtils.internals().concat([ 
     // ...
  ]);
}

@vadimdemedes
Copy link
Contributor

Probably adding those when debugging is enabled would be useful:

+       /[\\\/]ava[\\\/](?:lib[\\\/])?[\w-]+\.js:[0-9]+:[0-9]+\)?$/,
+       /[\\\/]node_modules[\\\/](?:bluebird|empower-core)[\\\/]/

@jamestalmage
Copy link
Contributor Author

If debugging is enabled, why not just print everything?

@vadimdemedes
Copy link
Contributor

Or that :)

@sindresorhus
Copy link
Member

😁

Looks kinda weird to have it double here:

false == true
AssertionError: false == true

Maybe we can remove the AssertionError?

found = found || relevant;
return !found || relevant;
function beautifyStack(stack) {
return stack.split('\n')[0] + '\n' + stackUtils.clean(stack).split('\n').map(function (s) {
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Why is the first line not indented? And why do we need to manually indent it? Shouldn't stack-utils do that for us?

Copy link
Contributor

Choose a reason for hiding this comment

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

See tapjs/stack-utils#2 (comment), if I'm not mistaken

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep. Whitespace at the beginning of any multi-line string makes the yaml output much harder to read. stack-utils trims whitespace from the first line.

I guess we could add an indent option to stack-utils.

Copy link
Member

Choose a reason for hiding this comment

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

I guess we could add an indent option to stack-utils.

👍 Can you open an issue on stack-utils so we don't forget to simplify this?

@jamestalmage
Copy link
Contributor Author

Maybe we can remove the AssertionError?

Sure. stack-utils actually chops the first line of the stack-trace (the message) off anyways. I actually manually add it back in beautify-stacktrace.js. The issue is the reporters only show that for assertion errors. unhandledRejections and uncaughtExceptions would be different. We would just need to rework the reporters so it's their responsibility to print the message.

/\(internal\/[\w_-]+\.js:[0-9]+:[0-9]+\)$/,
/\(native\)$/,
/[\\\/]ava[\\\/](?:lib[\\\/])?[\w-]+\.js:[0-9]+:[0-9]+\)?$/,
/[\\\/]node_modules[\\\/](?:bluebird|empower-core)[\\\/]/
Copy link
Member

Choose a reason for hiding this comment

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

Can you normalize the paths in stack traces to forward slash? That way they're consistent on all systems and with the added benefit of simpler regex here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, stack-utils already does that. I'm not sure if it does it before the regexp gets applied, but it probably should.

@sindresorhus
Copy link
Member

We would just need to rework the reporters so it's their responsibility to print the message.

👍 Can you open a new issue about that? It's unrelated to this PR, just came to my mind when looking at your screenshots.

@ariporad
Copy link
Contributor

👍

@jamestalmage jamestalmage changed the title [WIP] Use stack-utils for nicer stack traces. Use stack-utils for nicer stack traces. Jan 14, 2016
@jamestalmage jamestalmage force-pushed the use-stack-utils branch 2 times, most recently from ebef6e4 to 0f16082 Compare January 14, 2016 04:26
sindresorhus added a commit that referenced this pull request Jan 14, 2016
Use stack-utils for nicer stack traces.
@sindresorhus sindresorhus merged commit 1a6dbc7 into avajs:master Jan 14, 2016
@sindresorhus
Copy link
Member

👍

@jamestalmage jamestalmage deleted the use-stack-utils branch January 14, 2016 21:48
@vadimdemedes
Copy link
Contributor

I think this feature should go into killer-feature list.

@sindresorhus
Copy link
Member

@vdemedes Go ahead ;)

@kevva
Copy link
Contributor

kevva commented Jan 14, 2016

This is super nice.

This pull request was closed.
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.

5 participants