Skip to content

Added option to show original locations and path in error #1

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

Merged
merged 6 commits into from
Dec 1, 2016

Conversation

scf4
Copy link

@scf4 scf4 commented Nov 26, 2016

No description provided.

@thebigredgeek
Copy link
Owner

@scf4 thanks! Can you update tests?

@thebigredgeek
Copy link
Owner

Also, this might work better via an options hash versus two separate booleans.

@scf4
Copy link
Author

scf4 commented Nov 29, 2016

Yeah that's a better idea, check the new commit.

Regarding tests I guess we'd need to use a real Apollo error object to test it properly. I don't have the time at the moment.

Edit: I'm not familiar with CircleCI so unsure why it's failing?

@thebigredgeek
Copy link
Owner

Looks like it's failing because undefined won't serialize, it will simply be omitted. You will probably need to update the code :(

@scf4
Copy link
Author

scf4 commented Nov 29, 2016

Should be good now :)

@thebigredgeek
Copy link
Owner

Can you update the test to make sure that the error retains the location and path after being passed through formatError? Also, can you update the docs? Thanks for the work on this @scf4.

Copy link
Owner

@thebigredgeek thebigredgeek left a comment

Choose a reason for hiding this comment

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

Oh whoops, nvm. I see. Tests and docs still need updates though.

Also, can you quickly describe the use case? Sorry, not trying to be difficult. Just wanna make sure we are making wise decisions regarding API design :)

]));

this._name = name;
this._humanized_message = message || '';
this._time_thrown = t;
this._data = d;
this._locations = (opts.showLocations && arguments[2] && arguments[2].locations)
Copy link
Owner

Choose a reason for hiding this comment

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

Why are you using arguments here rather than opts?

Copy link
Author

Choose a reason for hiding this comment

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

It's a truthy check of the opts. The line was initially below const t = (arguments[2] && arguments[2]... and I was keeping it brief, but I'll make the code a little clearer tomorrow!

The arguments come from the originalError in formatError.

options: {
showLocations: true,
showPath: false,
},
Copy link
Owner

Choose a reason for hiding this comment

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

Please test formatError to make sure things are serializing properly

@scf4
Copy link
Author

scf4 commented Nov 29, 2016

The error comes from the originalError object which is passed to formatError. What wouldn't be serialized properly?

My use case is preserving the path info so I know which query caused which error when running multiple. I don't personally need locations but it could be relevant to some!

@thebigredgeek
Copy link
Owner

It "should", but we want to add tests to make sure that if we create an error with such options, the options are preserved when the error is serialized out to the client

@thebigredgeek
Copy link
Owner

Will merge after tests are adding. Wanna be super safe. Also, still wondering the use case here. Wouldn't I need to manually pass the location and path into the error data payload? If that's the case, are the booleans even necessary?

@thebigredgeek
Copy link
Owner

@scf4 bump :)

@scf4
Copy link
Author

scf4 commented Dec 1, 2016

@thebigredgeek Apollo server adds the path and locations to errors by default.

@thebigredgeek
Copy link
Owner

It would need to know to add them to the data object in the error constructor though, wouldn't it?

@scf4
Copy link
Author

scf4 commented Dec 1, 2016

formatError has originalError.path and originalError.locations. It passes them to the new custom error, which checks its opts (added in createError) to see if they should be returned in the object from serialize(). They don't get serialized into the blah/::/blah string because they don't exist at that point.

@thebigredgeek
Copy link
Owner

Ahh I see now. Clever. Nice! Will merge in just a few

@thebigredgeek thebigredgeek merged commit d5ed772 into thebigredgeek:master Dec 1, 2016
@scf4
Copy link
Author

scf4 commented Dec 1, 2016

Awesome thanks!

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