Skip to content

Handle array of errors. - #289

Merged
richardpringle merged 1 commit into
masterfrom
handle-error-array
Apr 15, 2016
Merged

Handle array of errors.#289
richardpringle merged 1 commit into
masterfrom
handle-error-array

Conversation

@richardpringle

Copy link
Copy Markdown
Contributor

Temporary fix for strongloop/loopback#2123

Connect to strongloop/loopback#2123

@richardpringle

Copy link
Copy Markdown
Contributor Author

@bajtos, the test case here is a little weird, please advise.

Comment thread lib/rest-adapter.js Outdated
data.stack = err.stack;
if (process.env.NODE_ENV === 'production' || options.disableStackTrace) {
delete data.stack;
debug('Error in %s %s: %s', req.method, req.url, err.stack);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is redundant, because generateResponseError already prints a debug message. Please remove.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

On the second thought, I think it may be a bit surprising that generateResponseError prints a debug log as a side-effect. Even you, as an author, got confused.

I am proposing to remove the debug statement from generateResponseError, and add explicit debug() calls in all places where it makes sense. Please check the resulting debug output for both cases (single error, array of errors) to ensure the information printed is useful and easy to understand.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@bajtos
I didn't get confused, I just forgot to delete the line outside of generateResponseError. I think that the debug log should remain in generateResponseError as is. It will display the individual errors from the connector as well as the location in which they were aggregated.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fair enough 👍

@bajtos

bajtos commented Apr 7, 2016

Copy link
Copy Markdown
Member

the test case here is a little weird, please advise.

It looks good to me. What do you find weird? It's possible I am missing something.

@bajtos bajtos assigned richardpringle and unassigned bajtos Apr 7, 2016
@richardpringle

Copy link
Copy Markdown
Contributor Author

@bajtos
I just thought there should be a more simple way to verify that the error is correct instead of nesting requests.

@richardpringle
richardpringle force-pushed the handle-error-array branch 2 times, most recently from c496111 to 216a8f3 Compare April 7, 2016 18:18
Comment thread test/rest.test.js Outdated
var testError = new Error('expected test error');
var errArray = [testError, testError];

var expectedMessage =

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this variable is no longer used, could you please remove?

@bajtos

bajtos commented Apr 8, 2016

Copy link
Copy Markdown
Member

I just thought there should be a more simple way to verify that the error is correct instead of nesting requests.

I suppose you could simply check that the second request returns an error where details contains two entries and each entry has expected message? Such test will check less facts than your current implementation, but I think it should suffice.

Anyways, the current test looks good to me.

@bajtos

bajtos commented Apr 8, 2016

Copy link
Copy Markdown
Member

@richardpringle I found few nitpicks, see the comments above. The patch LGTM otherwise, no further review is necessary. Please back-port to 2.x too.

@richardpringle

Copy link
Copy Markdown
Contributor Author

@bajtos, changes made but I don't quite know what's going on with these failed tests...
There seem to be some unrelated error to my changes.

Otherwise this is ready to land.

@richardpringle

Copy link
Copy Markdown
Contributor Author

@slnode please test

@richardpringle

Copy link
Copy Markdown
Contributor Author

@bajtos, there are random dependency tests failing. I haven't looked at all of them but in connector-rest there are 3 tests failing only on node 0.10 on ubuntu and in lb-boot, linter is failing for node 5 on ubuntu and amazon. Linter is also failing on all platforms for lb-workspace.

I'll check to see if the master branch manages to pass CI but in the meantime, do you have any ideas?

@richardpringle

Copy link
Copy Markdown
Contributor Author

This build hasn't passed in 6 months...

Comment thread lib/rest-adapter.js Outdated
});

err =
new Error('Failed with multiple errors, see `details` for more information.');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nitpick: I personally prefer this style:

var err = new Error(
  'Failed with multiple errors, see `details` for more information.');

or even the following, which works better when the error message needs to be split onto multiple lines:

var msg =  'Failed with multiple errors, see `details` for more information.';
var err = new Error(msg);

Feel free to ignore this comment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@bajtos, I will not ignore this comment! Haha, I completely agree. While I'm not a huge fan of your first suggestion, I do prefer your second. I usually do that, not sure why I didn't this time.

Regardless, I fixed it

@bajtos

bajtos commented Apr 13, 2016

Copy link
Copy Markdown
Member

LGTM.

As for the failing CI builds of dependencies, I hate to say it, but we should ignore those random failures and simply land this PR.

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