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

Proper error handling [minor changes required]: fixing Object object error messages #1046

Closed
ghost opened this issue Jan 22, 2019 · 7 comments
Labels

Comments

@ghost
Copy link

ghost commented Jan 22, 2019

@hwillson for quite a while me and other GraphQL users were dealing with unclear error messages.

To name a few:

dotansimha/graphql-binding#173
#743
(and maybe, but I'm not sure) #1037

The impossibility of using custom error codes that Apollo offers and dealing with weird error messages makes it hard to handle errors in a complex application.

Long story short, I guess I've managed to find the possible cause (at line 110):

https://github.com/apollographql/graphql-tools/blob/2394f0c3a8b30dbd4435dd21019727e76e61b892/src/stitching/errors.ts#L104-L113

If the checkResultAndHandleErrors is called and there's an errors array contains only one error the resulting error will be an instance not of Error but rather Object, which will result in unexpected behaviour here - https://github.com/graphql/graphql-js/blob/c2bc19badebd208ff21849e8f579e7034631af42/src/execution/execute.js#L721 as a result of this logic https://github.com/graphql/graphql-js/blob/c2bc19badebd208ff21849e8f579e7034631af42/src/execution/execute.js#L753-L758

In my opinion, the simplest solution would be to have something like this:

  if (result.errors && (!result.data || result.data[responseKey] == null)) {
    // apollo-link-http & http-link-dataloader need the
    // result property to be passed through for better error handling.
    // If there is only one error, which contains a result property, pass the error through
    const newError =
      result.errors.length === 1 && hasResult(result.errors[0])
        // Setting the prototype of result.errors[0] to Error
        ? Object.setPrototypeOf(result.errors[0], Error.prototype)
        : new CombinedError(concatErrors(result.errors), result.errors);
    throw locatedError(newError, info.fieldNodes, responsePathAsArray(info.path));
 } 

@terion-name
Copy link

Very needed fix!

@marjandjokic
Copy link

Yes, this is really needed fix, as I have the same problem and proposed fix solves the problem

@fluggo
Copy link

fluggo commented Jan 25, 2019

Fix is perfect. Until it lands, I'm using the following equivalent workaround for our remote schemas:

this.link = new ApolloLink((operation: Operation, forward?: NextLink) => {
  return forward(operation).map(data => {
    if(data.errors) {
      for(const error of data.errors) {
        if(!(error instanceof Error))
            Object.setPrototypeOf(error, Error.prototype);
      }
    }

    return data;
  });
}).concat(link);

@hwillson hwillson added bug help wanted Extra attention is needed labels Jan 25, 2019
@tsbhangu
Copy link

tsbhangu commented Feb 4, 2019

Agreed! The errors keep getting swallowed and it's very annoying to go to the base layer application to try to figure out what the error is.

@robertontiu
Copy link

Any progress with this issue?

@hwillson hwillson self-assigned this Mar 7, 2019
yaacovCR pushed a commit to yaacovCR/graphql-tools-fork that referenced this issue Jun 12, 2019
Use new relocatedError function to update the original GraphQLErrors
with the new path. Addresses ardatan#743, ardatan#1037, ardatan#1046,
apollographql/apollo-server#1582.
yaacovCR pushed a commit to yaacovCR/graphql-tools-fork that referenced this issue Jun 18, 2019
Use new relocatedError function to update the original GraphQLErrors
with the new path. Addresses ardatan#743, ardatan#1037, ardatan#1046,
apollographql/apollo-server#1582.
yaacovCR pushed a commit to yaacovCR/graphql-tools-fork that referenced this issue Sep 22, 2019
Use new relocatedError function to update the original GraphQLErrors
with the new path. Addresses ardatan#743, ardatan#1037, ardatan#1046,
apollographql/apollo-server#1582.
yaacovCR pushed a commit to yaacovCR/graphql-tools-fork that referenced this issue Sep 22, 2019
Use new relocatedError function to update the original GraphQLErrors
with the new path. Addresses ardatan#743, ardatan#1037, ardatan#1046,
apollographql/apollo-server#1582.
yaacovCR pushed a commit to yaacovCR/graphql-tools-fork that referenced this issue Sep 22, 2019
Use new relocatedError function to update the original GraphQLErrors
with the new path. Addresses ardatan#743, ardatan#1037, ardatan#1046,
apollographql/apollo-server#1582.
yaacovCR pushed a commit to yaacovCR/graphql-tools-fork that referenced this issue Oct 3, 2019
Use new relocatedError function to update the original GraphQLErrors
with the new path. Addresses ardatan#743, ardatan#1037, ardatan#1046,
apollographql/apollo-server#1582.
yaacovCR pushed a commit to yaacovCR/graphql-tools-fork that referenced this issue Oct 25, 2019
Use new relocatedError function to update the original GraphQLErrors
with the new path. Addresses ardatan#743, ardatan#1037, ardatan#1046,
apollographql/apollo-server#1582.
yaacovCR pushed a commit to yaacovCR/graphql-tools-fork that referenced this issue Oct 25, 2019
Use new relocatedError function to update the original GraphQLErrors
with the new path. Addresses ardatan#743, ardatan#1037, ardatan#1046,
apollographql/apollo-server#1582.
yaacovCR pushed a commit to yaacovCR/graphql-tools-fork that referenced this issue Nov 4, 2019
Use new relocatedError function to update the original GraphQLErrors
with the new path. Addresses ardatan#743, ardatan#1037, ardatan#1046,
apollographql/apollo-server#1582.
yaacovCR pushed a commit to yaacovCR/graphql-tools-fork that referenced this issue Dec 31, 2019
Use new relocatedError function to update the original GraphQLErrors
with the new path. Addresses ardatan#743, ardatan#1037, ardatan#1046,
apollographql/apollo-server#1582.
yaacovCR pushed a commit to yaacovCR/graphql-tools-fork that referenced this issue Dec 31, 2019
Use new relocatedError function to update the original GraphQLErrors
with the new path. Addresses ardatan#743, ardatan#1037, ardatan#1046,
apollographql/apollo-server#1582.
yaacovCR pushed a commit to yaacovCR/graphql-tools-fork that referenced this issue Jan 8, 2020
Use new relocatedError function to update the original GraphQLErrors
with the new path. Addresses ardatan#743, ardatan#1037, ardatan#1046,
apollographql/apollo-server#1582.
yaacovCR pushed a commit to yaacovCR/graphql-tools-fork that referenced this issue Jan 21, 2020
Use new relocatedError function to update the original GraphQLErrors
with the new path. Addresses ardatan#743, ardatan#1037, ardatan#1046,
apollographql/apollo-server#1582.
yaacovCR pushed a commit to yaacovCR/graphql-tools-fork that referenced this issue Feb 27, 2020
Use new relocatedError function to update the original GraphQLErrors
with the new path. Addresses ardatan#743, ardatan#1037, ardatan#1046,
apollographql/apollo-server#1582.
yaacovCR pushed a commit to yaacovCR/graphql-tools-fork that referenced this issue Mar 26, 2020
Use new relocatedError function to update the original GraphQLErrors
with the new path. Addresses ardatan#743, ardatan#1037, ardatan#1046,
apollographql/apollo-server#1582.
yaacovCR pushed a commit to yaacovCR/graphql-tools-fork that referenced this issue Mar 26, 2020
Use new relocatedError function to update the original GraphQLErrors
with the new path. Addresses ardatan#743, ardatan#1037, ardatan#1046,
apollographql/apollo-server#1582.
@kamilkisiela
Copy link
Collaborator

We recently released an alpha version of GraphQL Tools (#1308) that should fix the issue.

Please update graphql-tools to next or run:

npx match-version graphql-tools next

Let us know if it solves the problem, we're counting for your feedback! :)

@kamilkisiela kamilkisiela removed the help wanted Extra attention is needed label Mar 27, 2020
@yaacovCR yaacovCR mentioned this issue Mar 27, 2020
22 tasks
@yaacovCR
Copy link
Collaborator

Folded into #1306

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants