graphile / crystal

🔮 Graphile's Crystal Monorepo; home to Grafast, PostGraphile, pg-introspection, pg-sql2 and much more!
https://graphile.org/
Other
12.49k stars 568 forks source link

Subscription error causes socket to disconnect #2080

Closed benjie closed 4 weeks ago

benjie commented 4 weeks ago

Summary

Error thrown during subscription execution results in websocket connection terminating due to secondary unhandled error whilst trying to handle the first error. This is related to the reworking of errors in https://github.com/graphile/crystal/pull/2036 and related PRs.

Steps to reproduce

Plugin:

    makeExtendSchemaPlugin({
      typeDefs: gql`
        extend type Subscription {
          error: Int
        }
      `,
      plans: {
        Subscription: {
          error: {
            subscribePlan() {
              return lambda(constant(3), () => {
                throw new Error("Testing error");
              });
            },
          },
        },
      },
    })

GraphQL request:

subscription {
  error
}

Expected results

Error rendered in GraphiQL but socket connection not terminated.

Actual results

{
  "errors": [
    {
      "message": "Socket closed with event 4500 Cannot read properties of undefined (reading 'message')",
      "stack": "Error: Socket closed with event 4500 Cannot read properties of undefined (reading 'message')\n    at Object.error (http://127.0.0.1:5678/:49:1285975)\n    at http://127.0.0.1:5678/:49:474548"
    }
  ]
}

Additional context

Originally reported by @gitrojones in https://github.com/benjie/ouch-my-finger/issues/12

The error is mishandled and throws an internal error instead. The handler is assuming originalError exists in grafast/prepare.js > output.