Open schettn opened 3 months ago
Error Masking in Yoga hides errors if they are not instance of GraphQLError
.
https://the-guild.dev/graphql/yoga-server/docs/features/error-masking
If you want to see the original error, you should either disable this behavior or use GraphQLError
as original error.
Also if you want to see original errors only for development purposes, see here; https://the-guild.dev/graphql/yoga-server/docs/features/error-masking#receive-original-error-in-development
I am aware of error masking.
The problem is that when throwing a GraphQLError with the originalError prop there is no originalError in the extensions of the response.
throw new GraphQLError(“Foo”, {
originalError: new Error(“Bar”)
})
But when I throw a regular error there is.
“If you want to see the original error, you should either disable this behavior or use GraphQLError as original error.”
This is not possible since for example libraries do not throw GraphQL errors.
i want to catch those errors and throw a GraphQLError with the added originalError.
“But when I throw a regular error there is.“. I am able to receive the originalError when I throw an Error; just not when I throw a GraphQLError /w originalError as described above.
You may try use createGraphQLError
export from graphql-yoga
See below
import { createGraphQLError } from 'graphql-yoga';
try {
// Some code that throws an error
throw new Error('Original error message');
} catch (originalError) {
// Attempt to initialize a GraphQLError with the original error
const graphQLError = createGraphQLError('A GraphQL error occurred', {
originalError,
});
}
The thing is https://github.com/dotansimha/graphql-yoga/blob/9efdc3831a517890dbb00c783d6da86c6a6d9b4e/packages/graphql-yoga/src/utils/mask-error.ts#L11
this line was never return ture if you create the GraphQLError
on your code.
I think it may some bug on Yoga side, but solution above can play as workaround
@neviaumi Thanks I will try it!
Describe the bug
When attempting to throw a
GraphQLError
object with an original error (such as an exception or an error object from another part of the system), the original error is not included in the resulting GraphQL response. Instead, the original error details get swallowed or ignored, resulting in a response that lacks critical debugging information.Your Example Website or App
.
Steps to Reproduce the Bug or Issue
Use this inside a resolver:
Expected behavior
When a
GraphQLError
is created with an original error, the details of the original error (such as the message, stack trace, and other relevant properties) should be accessible in the GraphQL response. This inclusion helps with debugging and understanding the root cause of the error.Screenshots or Videos
No response
Platform
@graphql-yoga/*
version(s): [e.g. 2.5.1]Additional context
No response