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

Callback returned from executionDidStart is not triggered when error occurs #3705

Closed
jsarafajr opened this issue Jan 23, 2020 · 2 comments
Closed
Labels
🍐 error-handling Pertaining to error handling (or lack thereof), not just for just general errors/bugs. 🔌 plugins Relates to the request pipeline plugin API

Comments

@jsarafajr
Copy link

I'm trying to implement a plugin that should receive an error when query execution fails. I have the following plugin code:

const plugin = {
  requestDidStart: () => {
    return {
      executionDidStart: () => {
        return (err) => {
          if (err) {
            console.log('never called');
          }
        };
      },

      didEncounterErrors: (err) => {
        console.log('this one is called');
      }
  };
}

When I throw an error in a resolver didEncounterErrors gets called but callback returned from executionDidStart does not.

After a quick debug I found that error is not re-thrown when result returned from execution has errors property: https://github.com/apollographql/apollo-server/blob/master/packages/apollo-server-core/src/requestPipeline.ts#L370

My assumption is that instead of calling didEncounterErrors it should probably call emitErrorAndThrow.

@brianjquinn
Copy link

brianjquinn commented Jan 23, 2020

you beat me to it. I was seeing slightly different behavior, however. When I throw an error in a resolver I was seeingdidEncounterErrors being called here: https://github.com/apollographql/apollo-server/blob/master/packages/apollo-server-core/src/requestPipeline.ts#L370 and then the executionDidStart callback (executionDidEnd) being called after without an error object being passed in: https://github.com/apollographql/apollo-server/blob/master/packages/apollo-server-core/src/requestPipeline.ts#L378.

In either case you would expect the *DidEnd() callback to be called first with an error object passed in and then the didEnounterErrors to be called after (just like it does with the parse and validation phases).

When I throw an error in a resolver didEncounterErrors gets called but callback returned from executionDidStart does not.

I think to correct that (^) statement you mean the callback is called but err is always undefined so you never enter that if block (which mirrors the behavior I described).

@abernix abernix added 🍐 error-handling Pertaining to error handling (or lack thereof), not just for just general errors/bugs. 🔌 plugins Relates to the request pipeline plugin API labels Dec 31, 2020
@glasser
Copy link
Member

glasser commented Jun 9, 2021

I think this is working as intended. Passing a single error to executionDidEnd doesn't make sense: execution can produce lots of errors, for various fields. You can look at requestContext.errors to see if there are errors.

@glasser glasser closed this as completed Jun 9, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🍐 error-handling Pertaining to error handling (or lack thereof), not just for just general errors/bugs. 🔌 plugins Relates to the request pipeline plugin API
Projects
None yet
Development

No branches or pull requests

4 participants