From 0f8b45555c1cd580f3e12d71841ca4232074cae4 Mon Sep 17 00:00:00 2001 From: Lukas Bloder Date: Mon, 4 Dec 2023 15:43:08 +0100 Subject: [PATCH 1/6] WIP: initial impl of handling errors in "handleException" instead of "onException" keep "onException" for backwards compat --- sentry-graphql/api/sentry-graphql.api | 4 +++- .../SentryDataFetcherExceptionHandler.java | 22 ++++++++++++++---- ...tryGenericDataFetcherExceptionHandler.java | 23 +++++++++++++++++-- .../SentryGraphqlExceptionHandler.java | 8 +++---- .../sentry/graphql/SentryInstrumentation.java | 11 ++++++--- .../SentryDataFetcherExceptionHandlerTest.kt | 2 +- ...yGenericDataFetcherExceptionHandlerTest.kt | 2 +- .../SentryInstrumentationAnotherTest.kt | 3 ++- .../graphql/SentryInstrumentationTest.kt | 3 ++- ...ryDataFetcherExceptionResolverAdapter.java | 7 ++++-- ...ryDataFetcherExceptionResolverAdapter.java | 7 ++++-- 11 files changed, 70 insertions(+), 22 deletions(-) diff --git a/sentry-graphql/api/sentry-graphql.api b/sentry-graphql/api/sentry-graphql.api index 58e864d0b48..57c253e23cf 100644 --- a/sentry-graphql/api/sentry-graphql.api +++ b/sentry-graphql/api/sentry-graphql.api @@ -32,18 +32,20 @@ public final class io/sentry/graphql/NoOpSubscriptionHandler : io/sentry/graphql public final class io/sentry/graphql/SentryDataFetcherExceptionHandler : graphql/execution/DataFetcherExceptionHandler { public fun (Lgraphql/execution/DataFetcherExceptionHandler;)V public fun (Lio/sentry/IHub;Lgraphql/execution/DataFetcherExceptionHandler;)V + public fun handleException (Lgraphql/execution/DataFetcherExceptionHandlerParameters;)Ljava/util/concurrent/CompletableFuture; public fun onException (Lgraphql/execution/DataFetcherExceptionHandlerParameters;)Lgraphql/execution/DataFetcherExceptionHandlerResult; } public final class io/sentry/graphql/SentryGenericDataFetcherExceptionHandler : graphql/execution/DataFetcherExceptionHandler { public fun (Lgraphql/execution/DataFetcherExceptionHandler;)V public fun (Lio/sentry/IHub;Lgraphql/execution/DataFetcherExceptionHandler;)V + public fun handleException (Lgraphql/execution/DataFetcherExceptionHandlerParameters;)Ljava/util/concurrent/CompletableFuture; public fun onException (Lgraphql/execution/DataFetcherExceptionHandlerParameters;)Lgraphql/execution/DataFetcherExceptionHandlerResult; } public final class io/sentry/graphql/SentryGraphqlExceptionHandler { public fun (Lgraphql/execution/DataFetcherExceptionHandler;)V - public fun onException (Ljava/lang/Throwable;Lgraphql/schema/DataFetchingEnvironment;Lgraphql/execution/DataFetcherExceptionHandlerParameters;)Lgraphql/execution/DataFetcherExceptionHandlerResult; + public fun handleException (Ljava/lang/Throwable;Lgraphql/schema/DataFetchingEnvironment;Lgraphql/execution/DataFetcherExceptionHandlerParameters;)Ljava/util/concurrent/CompletableFuture; } public final class io/sentry/graphql/SentryInstrumentation : graphql/execution/instrumentation/SimpleInstrumentation { diff --git a/sentry-graphql/src/main/java/io/sentry/graphql/SentryDataFetcherExceptionHandler.java b/sentry-graphql/src/main/java/io/sentry/graphql/SentryDataFetcherExceptionHandler.java index 1e06d0b3220..22fbe938395 100644 --- a/sentry-graphql/src/main/java/io/sentry/graphql/SentryDataFetcherExceptionHandler.java +++ b/sentry-graphql/src/main/java/io/sentry/graphql/SentryDataFetcherExceptionHandler.java @@ -10,7 +10,9 @@ import io.sentry.IHub; import io.sentry.SentryIntegrationPackageStorage; import io.sentry.util.Objects; +import java.util.concurrent.CompletableFuture; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * Captures exceptions that occur during data fetching, passes them to Sentry and invokes a delegate @@ -36,13 +38,25 @@ public SentryDataFetcherExceptionHandler(final @NotNull DataFetcherExceptionHand } @Override - @SuppressWarnings("deprecation") - public DataFetcherExceptionHandlerResult onException( - final @NotNull DataFetcherExceptionHandlerParameters handlerParameters) { + public CompletableFuture handleException( + DataFetcherExceptionHandlerParameters handlerParameters) { final Hint hint = new Hint(); hint.set(GRAPHQL_HANDLER_PARAMETERS, handlerParameters); hub.captureException(handlerParameters.getException(), hint); - return delegate.onException(handlerParameters); + return delegate.handleException(handlerParameters); + } + + @SuppressWarnings("deprecation") + public DataFetcherExceptionHandlerResult onException( + final @NotNull DataFetcherExceptionHandlerParameters handlerParameters) { + final @Nullable CompletableFuture futureResult = + handleException(handlerParameters); + + if (futureResult != null) { + return futureResult.join(); + } else { + return CompletableFuture.completedFuture((DataFetcherExceptionHandlerResult) null).join(); + } } } diff --git a/sentry-graphql/src/main/java/io/sentry/graphql/SentryGenericDataFetcherExceptionHandler.java b/sentry-graphql/src/main/java/io/sentry/graphql/SentryGenericDataFetcherExceptionHandler.java index 4b7d72e2cd4..7122971c709 100644 --- a/sentry-graphql/src/main/java/io/sentry/graphql/SentryGenericDataFetcherExceptionHandler.java +++ b/sentry-graphql/src/main/java/io/sentry/graphql/SentryGenericDataFetcherExceptionHandler.java @@ -3,7 +3,10 @@ import graphql.execution.DataFetcherExceptionHandler; import graphql.execution.DataFetcherExceptionHandlerParameters; import graphql.execution.DataFetcherExceptionHandlerResult; +import graphql.execution.SimpleDataFetcherExceptionHandler; import io.sentry.IHub; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -24,11 +27,27 @@ public SentryGenericDataFetcherExceptionHandler( this(null, delegate); } - @Override @SuppressWarnings("deprecation") public @Nullable DataFetcherExceptionHandlerResult onException( final @NotNull DataFetcherExceptionHandlerParameters handlerParameters) { - return handler.onException( + CompletableFuture futureResult = + handleException(handlerParameters); + + if (futureResult == null) { + return CompletableFuture.completedFuture((DataFetcherExceptionHandlerResult) null).join(); + } + + try { + return futureResult.get(); + } catch (InterruptedException | ExecutionException e) { + return CompletableFuture.completedFuture((DataFetcherExceptionHandlerResult) null).join(); + } + } + + @Override + public @Nullable CompletableFuture handleException( + DataFetcherExceptionHandlerParameters handlerParameters) { + return handler.handleException( handlerParameters.getException(), handlerParameters.getDataFetchingEnvironment(), handlerParameters); diff --git a/sentry-graphql/src/main/java/io/sentry/graphql/SentryGraphqlExceptionHandler.java b/sentry-graphql/src/main/java/io/sentry/graphql/SentryGraphqlExceptionHandler.java index 527935f863e..c6fbf0b9dd4 100644 --- a/sentry-graphql/src/main/java/io/sentry/graphql/SentryGraphqlExceptionHandler.java +++ b/sentry-graphql/src/main/java/io/sentry/graphql/SentryGraphqlExceptionHandler.java @@ -8,6 +8,7 @@ import graphql.execution.DataFetcherExceptionHandlerResult; import graphql.schema.DataFetchingEnvironment; import java.util.List; +import java.util.concurrent.CompletableFuture; import java.util.concurrent.CopyOnWriteArrayList; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; @@ -22,8 +23,7 @@ public SentryGraphqlExceptionHandler(final @Nullable DataFetcherExceptionHandler this.delegate = delegate; } - @SuppressWarnings("deprecation") - public @Nullable DataFetcherExceptionHandlerResult onException( + public @Nullable CompletableFuture handleException( final @NotNull Throwable throwable, final @Nullable DataFetchingEnvironment environment, final @Nullable DataFetcherExceptionHandlerParameters handlerParameters) { @@ -40,9 +40,9 @@ public SentryGraphqlExceptionHandler(final @Nullable DataFetcherExceptionHandler } } if (delegate != null) { - return delegate.onException(handlerParameters); + return delegate.handleException(handlerParameters); } else { - return null; + return CompletableFuture.completedFuture(null); } } } diff --git a/sentry-graphql/src/main/java/io/sentry/graphql/SentryInstrumentation.java b/sentry-graphql/src/main/java/io/sentry/graphql/SentryInstrumentation.java index bd53bb57f21..aa6c7f62e26 100644 --- a/sentry-graphql/src/main/java/io/sentry/graphql/SentryInstrumentation.java +++ b/sentry-graphql/src/main/java/io/sentry/graphql/SentryInstrumentation.java @@ -8,7 +8,6 @@ import graphql.execution.ExecutionStepInfo; import graphql.execution.instrumentation.InstrumentationContext; import graphql.execution.instrumentation.InstrumentationState; -import graphql.execution.instrumentation.SimpleInstrumentation; import graphql.execution.instrumentation.parameters.InstrumentationExecuteOperationParameters; import graphql.execution.instrumentation.parameters.InstrumentationExecutionParameters; import graphql.execution.instrumentation.parameters.InstrumentationFieldFetchParameters; @@ -37,7 +36,8 @@ import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.TestOnly; -public final class SentryInstrumentation extends SimpleInstrumentation { +@SuppressWarnings("deprecation") +public final class SentryInstrumentation extends graphql.execution.instrumentation.SimpleInstrumentation { private static final @NotNull List ERROR_TYPES_HANDLED_BY_DATA_FETCHERS = Arrays.asList( @@ -161,11 +161,13 @@ public SentryInstrumentation( } @Override + @SuppressWarnings("deprecation") public @NotNull InstrumentationState createState() { return new TracingState(); } @Override + @SuppressWarnings("deprecation") public @NotNull InstrumentationContext beginExecution( final @NotNull InstrumentationExecutionParameters parameters) { final TracingState tracingState = parameters.getInstrumentationState(); @@ -176,6 +178,7 @@ public SentryInstrumentation( } @Override + @SuppressWarnings("deprecation") public CompletableFuture instrumentExecutionResult( ExecutionResult executionResult, InstrumentationExecutionParameters parameters) { return super.instrumentExecutionResult(executionResult, parameters) @@ -246,6 +249,7 @@ private boolean isIgnored(final @Nullable String errorType) { } @Override + @SuppressWarnings("deprecation") public @NotNull InstrumentationContext beginExecuteOperation( final @NotNull InstrumentationExecuteOperationParameters parameters) { final @Nullable ExecutionContext executionContext = parameters.getExecutionContext(); @@ -276,7 +280,8 @@ private boolean isIgnored(final @Nullable String errorType) { } @Override - @SuppressWarnings("FutureReturnValueIgnored") + @SuppressWarnings({"FutureReturnValueIgnored", "deprecation"}) + public @NotNull DataFetcher instrumentDataFetcher( final @NotNull DataFetcher dataFetcher, final @NotNull InstrumentationFieldFetchParameters parameters) { diff --git a/sentry-graphql/src/test/kotlin/io/sentry/graphql/SentryDataFetcherExceptionHandlerTest.kt b/sentry-graphql/src/test/kotlin/io/sentry/graphql/SentryDataFetcherExceptionHandlerTest.kt index 0157c638199..b571fa82183 100644 --- a/sentry-graphql/src/test/kotlin/io/sentry/graphql/SentryDataFetcherExceptionHandlerTest.kt +++ b/sentry-graphql/src/test/kotlin/io/sentry/graphql/SentryDataFetcherExceptionHandlerTest.kt @@ -23,6 +23,6 @@ class SentryDataFetcherExceptionHandlerTest { handler.onException(parameters) verify(hub).captureException(eq(exception), anyOrNull()) - verify(delegate).onException(parameters) + verify(delegate).handleException(parameters) } } diff --git a/sentry-graphql/src/test/kotlin/io/sentry/graphql/SentryGenericDataFetcherExceptionHandlerTest.kt b/sentry-graphql/src/test/kotlin/io/sentry/graphql/SentryGenericDataFetcherExceptionHandlerTest.kt index 62ac134212c..6d643baf017 100644 --- a/sentry-graphql/src/test/kotlin/io/sentry/graphql/SentryGenericDataFetcherExceptionHandlerTest.kt +++ b/sentry-graphql/src/test/kotlin/io/sentry/graphql/SentryGenericDataFetcherExceptionHandlerTest.kt @@ -36,6 +36,6 @@ class SentryGenericDataFetcherExceptionHandlerTest { assertNotNull(exceptions) assertEquals(1, exceptions.size) assertEquals(exception, exceptions.first()) - verify(delegate).onException(parameters) + verify(delegate).handleException(parameters) } } diff --git a/sentry-graphql/src/test/kotlin/io/sentry/graphql/SentryInstrumentationAnotherTest.kt b/sentry-graphql/src/test/kotlin/io/sentry/graphql/SentryInstrumentationAnotherTest.kt index b8bc76388c6..867824e7801 100644 --- a/sentry-graphql/src/test/kotlin/io/sentry/graphql/SentryInstrumentationAnotherTest.kt +++ b/sentry-graphql/src/test/kotlin/io/sentry/graphql/SentryInstrumentationAnotherTest.kt @@ -131,7 +131,8 @@ class SentryInstrumentationAnotherTest { it.transaction = activeSpan } } - fieldFetchParameters = InstrumentationFieldFetchParameters(executionContext, environment, executionStrategyParameters, false).withNewState( + fieldFetchParameters = InstrumentationFieldFetchParameters(executionContext, + { environment } , executionStrategyParameters, false).withNewState( instrumentationState ) val executionInput = ExecutionInput.newExecutionInput() diff --git a/sentry-graphql/src/test/kotlin/io/sentry/graphql/SentryInstrumentationTest.kt b/sentry-graphql/src/test/kotlin/io/sentry/graphql/SentryInstrumentationTest.kt index 2294a6aa9c8..3830f3294be 100644 --- a/sentry-graphql/src/test/kotlin/io/sentry/graphql/SentryInstrumentationTest.kt +++ b/sentry-graphql/src/test/kotlin/io/sentry/graphql/SentryInstrumentationTest.kt @@ -193,7 +193,8 @@ class SentryInstrumentationTest { .fields(MergedSelectionSet.newMergedSelectionSet().build()) .field(MergedField.newMergedField().addField(Field.newField("myFieldName").build()).build()) .build() - val parameters = InstrumentationFieldFetchParameters(executionContext, environment, executionStrategyParameters, false).withNewState(SentryInstrumentation.TracingState()) + val parameters = InstrumentationFieldFetchParameters(executionContext, + { environment }, executionStrategyParameters, false).withNewState(SentryInstrumentation.TracingState()) val instrumentedDataFetcher = instrumentation.instrumentDataFetcher(dataFetcher, parameters) val result = instrumentedDataFetcher.get(environment) diff --git a/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/graphql/SentryDataFetcherExceptionResolverAdapter.java b/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/graphql/SentryDataFetcherExceptionResolverAdapter.java index c70830e52a2..3f34931147c 100644 --- a/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/graphql/SentryDataFetcherExceptionResolverAdapter.java +++ b/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/graphql/SentryDataFetcherExceptionResolverAdapter.java @@ -5,6 +5,7 @@ import graphql.schema.DataFetchingEnvironment; import io.sentry.graphql.SentryGraphqlExceptionHandler; import java.util.List; +import java.util.concurrent.CompletableFuture; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -36,9 +37,11 @@ public boolean isThreadLocalContextAware() { @Override protected @Nullable List resolveToMultipleErrors( Throwable ex, DataFetchingEnvironment env) { - @Nullable DataFetcherExceptionHandlerResult result = handler.onException(ex, env, null); + @Nullable + CompletableFuture result = + handler.handleException(ex, env, null); if (result != null) { - return result.getErrors(); + return result.join().getErrors(); } return null; } diff --git a/sentry-spring/src/main/java/io/sentry/spring/graphql/SentryDataFetcherExceptionResolverAdapter.java b/sentry-spring/src/main/java/io/sentry/spring/graphql/SentryDataFetcherExceptionResolverAdapter.java index c52823653e4..16ebe0ce8c3 100644 --- a/sentry-spring/src/main/java/io/sentry/spring/graphql/SentryDataFetcherExceptionResolverAdapter.java +++ b/sentry-spring/src/main/java/io/sentry/spring/graphql/SentryDataFetcherExceptionResolverAdapter.java @@ -5,6 +5,7 @@ import graphql.schema.DataFetchingEnvironment; import io.sentry.graphql.SentryGraphqlExceptionHandler; import java.util.List; +import java.util.concurrent.CompletableFuture; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -36,9 +37,11 @@ public boolean isThreadLocalContextAware() { @Override protected @Nullable List resolveToMultipleErrors( Throwable ex, DataFetchingEnvironment env) { - @Nullable DataFetcherExceptionHandlerResult result = handler.onException(ex, env, null); + @Nullable + CompletableFuture result = + handler.handleException(ex, env, null); if (result != null) { - return result.getErrors(); + return result.join().getErrors(); } return null; } From ae6c65c2a9b48fe5ab2f376378941cccdca987bd Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Mon, 11 Dec 2023 09:31:22 +0000 Subject: [PATCH 2/6] Format code --- .../graphql/SentryGenericDataFetcherExceptionHandler.java | 1 - .../java/io/sentry/graphql/SentryInstrumentation.java | 4 ++-- .../io/sentry/graphql/SentryInstrumentationAnotherTest.kt | 8 ++++++-- .../kotlin/io/sentry/graphql/SentryInstrumentationTest.kt | 8 ++++++-- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/sentry-graphql/src/main/java/io/sentry/graphql/SentryGenericDataFetcherExceptionHandler.java b/sentry-graphql/src/main/java/io/sentry/graphql/SentryGenericDataFetcherExceptionHandler.java index 7122971c709..5c3bd676558 100644 --- a/sentry-graphql/src/main/java/io/sentry/graphql/SentryGenericDataFetcherExceptionHandler.java +++ b/sentry-graphql/src/main/java/io/sentry/graphql/SentryGenericDataFetcherExceptionHandler.java @@ -3,7 +3,6 @@ import graphql.execution.DataFetcherExceptionHandler; import graphql.execution.DataFetcherExceptionHandlerParameters; import graphql.execution.DataFetcherExceptionHandlerResult; -import graphql.execution.SimpleDataFetcherExceptionHandler; import io.sentry.IHub; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; diff --git a/sentry-graphql/src/main/java/io/sentry/graphql/SentryInstrumentation.java b/sentry-graphql/src/main/java/io/sentry/graphql/SentryInstrumentation.java index aa6c7f62e26..d2d62c99d84 100644 --- a/sentry-graphql/src/main/java/io/sentry/graphql/SentryInstrumentation.java +++ b/sentry-graphql/src/main/java/io/sentry/graphql/SentryInstrumentation.java @@ -37,7 +37,8 @@ import org.jetbrains.annotations.TestOnly; @SuppressWarnings("deprecation") -public final class SentryInstrumentation extends graphql.execution.instrumentation.SimpleInstrumentation { +public final class SentryInstrumentation + extends graphql.execution.instrumentation.SimpleInstrumentation { private static final @NotNull List ERROR_TYPES_HANDLED_BY_DATA_FETCHERS = Arrays.asList( @@ -281,7 +282,6 @@ private boolean isIgnored(final @Nullable String errorType) { @Override @SuppressWarnings({"FutureReturnValueIgnored", "deprecation"}) - public @NotNull DataFetcher instrumentDataFetcher( final @NotNull DataFetcher dataFetcher, final @NotNull InstrumentationFieldFetchParameters parameters) { diff --git a/sentry-graphql/src/test/kotlin/io/sentry/graphql/SentryInstrumentationAnotherTest.kt b/sentry-graphql/src/test/kotlin/io/sentry/graphql/SentryInstrumentationAnotherTest.kt index 867824e7801..23e18af4782 100644 --- a/sentry-graphql/src/test/kotlin/io/sentry/graphql/SentryInstrumentationAnotherTest.kt +++ b/sentry-graphql/src/test/kotlin/io/sentry/graphql/SentryInstrumentationAnotherTest.kt @@ -131,8 +131,12 @@ class SentryInstrumentationAnotherTest { it.transaction = activeSpan } } - fieldFetchParameters = InstrumentationFieldFetchParameters(executionContext, - { environment } , executionStrategyParameters, false).withNewState( + fieldFetchParameters = InstrumentationFieldFetchParameters( + executionContext, + { environment }, + executionStrategyParameters, + false + ).withNewState( instrumentationState ) val executionInput = ExecutionInput.newExecutionInput() diff --git a/sentry-graphql/src/test/kotlin/io/sentry/graphql/SentryInstrumentationTest.kt b/sentry-graphql/src/test/kotlin/io/sentry/graphql/SentryInstrumentationTest.kt index 3830f3294be..013053cac89 100644 --- a/sentry-graphql/src/test/kotlin/io/sentry/graphql/SentryInstrumentationTest.kt +++ b/sentry-graphql/src/test/kotlin/io/sentry/graphql/SentryInstrumentationTest.kt @@ -193,8 +193,12 @@ class SentryInstrumentationTest { .fields(MergedSelectionSet.newMergedSelectionSet().build()) .field(MergedField.newMergedField().addField(Field.newField("myFieldName").build()).build()) .build() - val parameters = InstrumentationFieldFetchParameters(executionContext, - { environment }, executionStrategyParameters, false).withNewState(SentryInstrumentation.TracingState()) + val parameters = InstrumentationFieldFetchParameters( + executionContext, + { environment }, + executionStrategyParameters, + false + ).withNewState(SentryInstrumentation.TracingState()) val instrumentedDataFetcher = instrumentation.instrumentDataFetcher(dataFetcher, parameters) val result = instrumentedDataFetcher.get(environment) From 50c5f0737278d51e008bafc97b53dfbccf0f2455 Mon Sep 17 00:00:00 2001 From: Lukas Bloder Date: Mon, 11 Dec 2023 13:50:12 +0100 Subject: [PATCH 3/6] add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ee5e782434..734eeae7aab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Features - Support multiple debug-metadata.properties ([#3024](https://github.com/getsentry/sentry-java/pull/3024)) +- Add support for `graphql-java` version 21 ([#3090](https://github.com/getsentry/sentry-java/pull/3090)) ### Fixes From 223e02035757d3bdb34a220ca718e359d88fe000 Mon Sep 17 00:00:00 2001 From: Lukas Bloder Date: Mon, 11 Dec 2023 15:35:24 +0100 Subject: [PATCH 4/6] revert tests for compatibility with graphql-java 17.3 --- .../io/sentry/graphql/SentryInstrumentationAnotherTest.kt | 2 +- .../test/kotlin/io/sentry/graphql/SentryInstrumentationTest.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sentry-graphql/src/test/kotlin/io/sentry/graphql/SentryInstrumentationAnotherTest.kt b/sentry-graphql/src/test/kotlin/io/sentry/graphql/SentryInstrumentationAnotherTest.kt index 23e18af4782..e30bbc9415e 100644 --- a/sentry-graphql/src/test/kotlin/io/sentry/graphql/SentryInstrumentationAnotherTest.kt +++ b/sentry-graphql/src/test/kotlin/io/sentry/graphql/SentryInstrumentationAnotherTest.kt @@ -133,7 +133,7 @@ class SentryInstrumentationAnotherTest { } fieldFetchParameters = InstrumentationFieldFetchParameters( executionContext, - { environment }, + environment, executionStrategyParameters, false ).withNewState( diff --git a/sentry-graphql/src/test/kotlin/io/sentry/graphql/SentryInstrumentationTest.kt b/sentry-graphql/src/test/kotlin/io/sentry/graphql/SentryInstrumentationTest.kt index 013053cac89..8a579e26876 100644 --- a/sentry-graphql/src/test/kotlin/io/sentry/graphql/SentryInstrumentationTest.kt +++ b/sentry-graphql/src/test/kotlin/io/sentry/graphql/SentryInstrumentationTest.kt @@ -195,7 +195,7 @@ class SentryInstrumentationTest { .build() val parameters = InstrumentationFieldFetchParameters( executionContext, - { environment }, + environment, executionStrategyParameters, false ).withNewState(SentryInstrumentation.TracingState()) From 4f304fde6b1f09af09a8987896458ce48afa9401 Mon Sep 17 00:00:00 2001 From: Lukas Bloder Date: Mon, 18 Dec 2023 16:18:22 +0100 Subject: [PATCH 5/6] CR --- .../SentryDataFetcherExceptionHandler.java | 11 ++++++++--- ...SentryGenericDataFetcherExceptionHandler.java | 16 ++++++++-------- .../graphql/SentryGraphqlExceptionHandler.java | 2 +- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/sentry-graphql/src/main/java/io/sentry/graphql/SentryDataFetcherExceptionHandler.java b/sentry-graphql/src/main/java/io/sentry/graphql/SentryDataFetcherExceptionHandler.java index 22fbe938395..97d3c4edf60 100644 --- a/sentry-graphql/src/main/java/io/sentry/graphql/SentryDataFetcherExceptionHandler.java +++ b/sentry-graphql/src/main/java/io/sentry/graphql/SentryDataFetcherExceptionHandler.java @@ -11,6 +11,7 @@ import io.sentry.SentryIntegrationPackageStorage; import io.sentry.util.Objects; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -48,15 +49,19 @@ public CompletableFuture handleException( } @SuppressWarnings("deprecation") - public DataFetcherExceptionHandlerResult onException( + public @Nullable DataFetcherExceptionHandlerResult onException( final @NotNull DataFetcherExceptionHandlerParameters handlerParameters) { final @Nullable CompletableFuture futureResult = handleException(handlerParameters); if (futureResult != null) { - return futureResult.join(); + try { + return futureResult.get(); + } catch (InterruptedException | ExecutionException e) { + return null; + } } else { - return CompletableFuture.completedFuture((DataFetcherExceptionHandlerResult) null).join(); + return null; } } } diff --git a/sentry-graphql/src/main/java/io/sentry/graphql/SentryGenericDataFetcherExceptionHandler.java b/sentry-graphql/src/main/java/io/sentry/graphql/SentryGenericDataFetcherExceptionHandler.java index 5c3bd676558..6251d00779a 100644 --- a/sentry-graphql/src/main/java/io/sentry/graphql/SentryGenericDataFetcherExceptionHandler.java +++ b/sentry-graphql/src/main/java/io/sentry/graphql/SentryGenericDataFetcherExceptionHandler.java @@ -32,14 +32,14 @@ public SentryGenericDataFetcherExceptionHandler( CompletableFuture futureResult = handleException(handlerParameters); - if (futureResult == null) { - return CompletableFuture.completedFuture((DataFetcherExceptionHandlerResult) null).join(); - } - - try { - return futureResult.get(); - } catch (InterruptedException | ExecutionException e) { - return CompletableFuture.completedFuture((DataFetcherExceptionHandlerResult) null).join(); + if (futureResult != null) { + try { + return futureResult.get(); + } catch (InterruptedException | ExecutionException e) { + return null; + } + } else { + return null; } } diff --git a/sentry-graphql/src/main/java/io/sentry/graphql/SentryGraphqlExceptionHandler.java b/sentry-graphql/src/main/java/io/sentry/graphql/SentryGraphqlExceptionHandler.java index c6fbf0b9dd4..a1f94caccec 100644 --- a/sentry-graphql/src/main/java/io/sentry/graphql/SentryGraphqlExceptionHandler.java +++ b/sentry-graphql/src/main/java/io/sentry/graphql/SentryGraphqlExceptionHandler.java @@ -42,7 +42,7 @@ public SentryGraphqlExceptionHandler(final @Nullable DataFetcherExceptionHandler if (delegate != null) { return delegate.handleException(handlerParameters); } else { - return CompletableFuture.completedFuture(null); + return null; } } } From 378e3fdc9c4de74da2f3593820b7cc7757486a4a Mon Sep 17 00:00:00 2001 From: Lukas Bloder Date: Tue, 19 Dec 2023 16:10:05 +0100 Subject: [PATCH 6/6] remove @Nullable annotation and return empty result in SentryDataFetcherExceptionHandler onException --- .../sentry/graphql/SentryDataFetcherExceptionHandler.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sentry-graphql/src/main/java/io/sentry/graphql/SentryDataFetcherExceptionHandler.java b/sentry-graphql/src/main/java/io/sentry/graphql/SentryDataFetcherExceptionHandler.java index 97d3c4edf60..c0467c00891 100644 --- a/sentry-graphql/src/main/java/io/sentry/graphql/SentryDataFetcherExceptionHandler.java +++ b/sentry-graphql/src/main/java/io/sentry/graphql/SentryDataFetcherExceptionHandler.java @@ -49,7 +49,7 @@ public CompletableFuture handleException( } @SuppressWarnings("deprecation") - public @Nullable DataFetcherExceptionHandlerResult onException( + public DataFetcherExceptionHandlerResult onException( final @NotNull DataFetcherExceptionHandlerParameters handlerParameters) { final @Nullable CompletableFuture futureResult = handleException(handlerParameters); @@ -58,10 +58,10 @@ public CompletableFuture handleException( try { return futureResult.get(); } catch (InterruptedException | ExecutionException e) { - return null; + return DataFetcherExceptionHandlerResult.newResult().build(); } } else { - return null; + return DataFetcherExceptionHandlerResult.newResult().build(); } } }