-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
1.2.1 regression: dont crash if there is a single stackframe #605
Conversation
For info, comparing
|
I'm very curious about your setup. Can you share a minimal setup to reproduce this or add a feature test that captures your setup (fails without your changes and passes with them)? |
@charlierudolph tough one! But I hear you. Calling my colleagues (@floribon) to the rescue and reviewing the existing cucumber-js tests to try to spot the difference. |
@charlierudolph this happens when using custom stack traces as suggested in this thread #157 (comment) I am overriding the /** https://github.com/cucumber/cucumber-js/issues/157#issuecomment-43309248 **/
function setCleanStrackTraces() {
// monkey-patch stack trace more-or-less compatible with webdriver
const isMyStack = new RegExp(
path.join(
__dirname, '../../../..',
'[^node_modules/]' // exclude node_modules
).replace(/\//g, '\\/')
);
Error.prepareStackTrace = function (err, stack) {
let message = err
.message.split('\n')
.filter(s => !/Session|Driver|Build|System|Capabilities|Command/.test(s))
.join('\n') || '';
if (!message.trim()) {
// we would rather see something than not see something at all
message = '[internal] ' + err.message.split('\n')[0].trim();
}
if (message) { message += '\n'; }
const results = [];
for (const elt of stack) {
const frame = elt.toString();
if (isMyStack.test(frame)) {
results.push(' at ' + frame);
}
}
return message + results.join('\n');
};
} Unfortunately this is breaking since |
stackframes[i].fileName !== '(native)') { | ||
return stackframes[i]; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use lodash's _.find
here instead of the manual for loop and _.includes
instead of stackframes[i].fileName.indexOf
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually can this just be simplified to
var stackframes = StackTrace.getSync();
if (stackframes.length > 1) {
return stackframes[1];
} else {
return stackframes[0];
}
@charlierudolph PR updated with your suggested syntax, it does work for us |
function getStackframe() { | ||
var stackframes = StackTrace.getSync(); | ||
if (stackframes.length > 1) { | ||
return stackframes[1]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on the failing feature tests, I think this logic needs to actually be
if (stackframes.length > 2) {
return stackframes[2];
} // ...
Since the defineHook / defineStep is now calling this, we have another function on the stack and thus need to look one level further back.
Please add a unit test for this to prevent regressions. I believe you can stub out |
Regression from #538 In my setup there is either 1 stackframe or 8 of them. I am not sure this is the perfect fix but it does re-enable running the testsuite
@charlierudolph I am really sorry I did not follow the contributing guidelines. This time I ran the tests and my use case and everything works. However I studied the specs codebase but could not figure out how to add a unit test for this. |
@floribon let me see if I can help you through being able to write a unit test for it. The unit test would go in An example of mocking out another module's function What else can I help with? |
@charlierudolph are stacktrace outputs tested somewhere? I believe that's where one could make sure that it succeeds even if the user overrode Now reading more about #157 I realized that I could avoid the error by using these, which is cleaner:
So feel free to reject this PR if it is not helping. |
They are not tested anywhere at the moment. If you wanted you could just create a feature where you override |
Pushed, confirmed that it fails on master and passes on this branch. |
this.When(/^I override Error.prepareStackTrace$/, function() { | ||
Error.prepareStackTrace = function() { | ||
return 'Custom message'; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this doesn't fail for me on master. I would expect you to need to override it before this.When()
gets called as that is when the stacktrace is captured.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@charlierudolph my bad, it failed for me but because of the missing ✓
which I didn't see initially. I've just pushed an update for the test which this time I made sure were giving the error on master:
(...)/node_modules/cucumber/lib/cucumber/support_code/library.js:53
var line = stackframes[1].getLineNumber();
Thank you very much for your contribution! |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Regression from #538:
In my setup there is either 1 stackframe or 8 of them.
I am not sure this is the perfect fix but it does re-enable running the testsuite.