René's URL Explorer Experiment


Title: Difference in catch and reporting behavior of Coercing value errors vs literal errors · Issue #2811 · graphql-java/graphql-java · GitHub

Open Graph Title: Difference in catch and reporting behavior of Coercing value errors vs literal errors · Issue #2811 · graphql-java/graphql-java

X Title: Difference in catch and reporting behavior of Coercing value errors vs literal errors · Issue #2811 · graphql-java/graphql-java

Description: Describe the bug I've recently noticed a difference in behavior (using release 18.0) between how exceptions are handled implementing a custom scalar which parses input fields values and literals. As I understand them parseLiteral is used...

Open Graph Description: Describe the bug I've recently noticed a difference in behavior (using release 18.0) between how exceptions are handled implementing a custom scalar which parses input fields values and literals. A...

X Description: Describe the bug I've recently noticed a difference in behavior (using release 18.0) between how exceptions are handled implementing a custom scalar which parses input fields values and literal...

Opengraph URL: https://github.com/graphql-java/graphql-java/issues/2811

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Difference in catch and reporting behavior of Coercing value errors vs literal errors","articleBody":"**Describe the bug**\r\n\r\nI've recently noticed a difference in behavior (using release 18.0) between how exceptions are handled implementing a custom scalar which parses input fields values and literals.\r\n\r\nAs I understand them `parseLiteral` is used in the case where an input comes directly from a query. This works well [as described in the docs](https://www.graphql-java.com/documentation/scalars/) when the custom `Coercing` throws a `CoercingParseLiteralException` exception. The error is handled by the execution engine and serialized with normal graphql errors according to the spec in the responses `errors` array.\r\n\r\nHowever, when the same input comes from a query variable, `parseValue` is used and, as the [as described in the docs](https://www.graphql-java.com/documentation/scalars/) mention, I throw `CoercingParseValueException` exception. In the case the execution engine does not catch and handle the exception and instead it results in a 500 error from my server rather than a 200 response with a graphql errors spec response.\r\n\r\nbelow is an example stack trace if it helps\r\n\r\n```\r\n2022-04-23 17:27:49,743 - - - [jetty task-169] ERROR org.jooby.Err  - execution of: POST/ resulted in exception\r\nRoute:\r\n      | Method | Path | Source                                     | Name       | Pattern | Consumes | Produces |\r\n      |--------|------|--------------------------------------------|------------|---------|----------|----------|\r\n      | POST   | /    | com.meetup.graphql.server.GraphqlServer:66 | /anonymous | /       | [*/*]    | [*/*]    |\r\n\r\nStacktrace:\r\norg.jooby.Err: Server Error(500)\r\n        \u003csnip\u003e\r\nCaused by: graphql.schema.CoercingParseValueException: Variable 'startDateTime' has an invalid value: Try something like '2022-04-24T17:27' instead\r\n        at graphql.schema.CoercingParseValueException$Builder.build(CoercingParseValueException.java:46)\r\n        at graphql.execution.ValuesResolver.externalValueToInternalValueForVariables(ValuesResolver.java:420)\r\n        at graphql.execution.ValuesResolver.coerceVariableValues(ValuesResolver.java:94)\r\n        at graphql.analysis.QueryTraverser.coerceVariables(QueryTraverser.java:64)\r\n        at graphql.analysis.QueryTraverser.\u003cinit\u003e(QueryTraverser.java:60)\r\n        at graphql.analysis.QueryTraverser.\u003cinit\u003e(QueryTraverser.java:40)\r\n        at graphql.analysis.QueryTraverser$Builder.build(QueryTraverser.java:297)\r\n        at graphql.analysis.MaxQueryComplexityInstrumentation.newQueryTraverser(MaxQueryComplexityInstrumentation.java:134)\r\n        at graphql.analysis.MaxQueryComplexityInstrumentation.lambda$beginValidation$4(MaxQueryComplexityInstrumentation.java:85)\r\n        at graphql.execution.instrumentation.SimpleInstrumentationContext.onCompleted(SimpleInstrumentationContext.java:51)\r\n        at graphql.execution.instrumentation.ChainedInstrumentation$ChainedInstrumentationContext.lambda$onCompleted$1(ChainedInstrumentation.java:238)\r\n        at graphql.com.google.common.collect.ImmutableList.forEach(ImmutableList.java:422)\r\n        at graphql.execution.instrumentation.ChainedInstrumentation$ChainedInstrumentationContext.onCompleted(ChainedInstrumentation.java:238)\r\n        at graphql.GraphQL.validate(GraphQL.java:628)\r\n        at graphql.GraphQL.parseAndValidate(GraphQL.java:589)\r\n        at graphql.GraphQL.lambda$parseValidateAndExecute$10(GraphQL.java:553)\r\n        at com.meetup.graphql.server.GraphqlServer.lambda$new$0(GraphqlServer.java:59)\r\n        at java.base/java.util.HashMap.computeIfAbsent(HashMap.java:1134)\r\n        at java.base/java.util.Collections$SynchronizedMap.computeIfAbsent(Collections.java:2682)\r\n        at com.meetup.graphql.server.GraphqlServer.lambda$new$1(GraphqlServer.java:59)\r\n        at graphql.execution.preparsed.PreparsedDocumentProvider.getDocumentAsync(PreparsedDocumentProvider.java:45)\r\n        at graphql.GraphQL.parseValidateAndExecute(GraphQL.java:555)\r\n        at graphql.GraphQL.executeAsync(GraphQL.java:524)\r\n        at graphql.GraphQL.execute(GraphQL.java:450)\r\n        at com.meetup.graphql.server.GraphqlQueryExecutor.toExecutionResult(GraphqlQueryExecutor.java:93)\r\n        at com.meetup.graphql.server.GraphqlHandler.handle(GraphqlHandler.java:82)\r\n        at com.meetup.graphql.server.GraphqlServer.lambda$new$2(GraphqlServer.java:79)\r\n        at org.jooby.Route$Handler.handle(Route.java:1761)\r\n        at org.jooby.internal.RouteImpl.handle(RouteImpl.java:280)\r\n        at org.jooby.internal.RouteChain.next(RouteChain.java:262)\r\n        at org.jooby.Route$Chain.next(Route.java:2164)\r\n        at org.jooby.internal.HttpHandlerImpl.handle(HttpHandlerImpl.java:496)\r\n        ... 19 more\r\nCaused by: java.time.format.DateTimeParseException: Text '2022-05-01T05:30+400' could not be parsed, unparsed text found at index 16\r\n        at java.base/java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:2049)\r\n        at java.base/java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1948)\r\n        at java.base/java.time.LocalDateTime.parse(LocalDateTime.java:492)\r\n```\r\n\r\n\r\n**To Reproduce**\r\n\r\nHere is what my `Coercing` scalar impl looks like. note parse value errors are reported with `CoercingParseValueException` and parse literal errors are reported with `CoercingParseLiteralException`\r\n\r\nwhen an invalid input is passed in a literal the execution engine does what I expect. when an invalid input is passed in through a variable, the exception bubbles all the way up to my server, resulting in a 500 error.\r\n\r\n```java\r\n  static java.time.LocalDateTime parseLocalDateTimeValue(Object input) {\r\n    String value =\r\n        input instanceof StringValue ? ((StringValue) input).getValue() : Objects.toString(input);\r\n    try {\r\n      if (input instanceof StringValue) {\r\n        return java.time.LocalDateTime.parse(value);\r\n      } else if (input instanceof String) {\r\n        return java.time.LocalDateTime.parse(value);\r\n      } else throw new IllegalArgumentException(\"Unexpected input type: \" + input.getClass());\r\n    } catch (Exception e) {\r\n      throw new CoercingParseValueException(\r\n          \"Try something like '\"\r\n              + java.time.LocalDateTime.now().truncatedTo(ChronoUnit.MINUTES).plusDays(1)\r\n              + \"' instead\",\r\n          e);\r\n    }\r\n  }\r\n\r\n  static java.time.LocalDateTime parseLocalDateTimeLiteral(Object input) {\r\n    String value =\r\n        input instanceof StringValue ? ((StringValue) input).getValue() : Objects.toString(input);\r\n    try {\r\n      if (input instanceof StringValue) {\r\n        return java.time.LocalDateTime.parse(value);\r\n      } else if (input instanceof String) {\r\n        return java.time.LocalDateTime.parse(value);\r\n      } else throw new IllegalArgumentException(\"Unexpected input type: \" + input.getClass());\r\n    } catch (Exception e) {\r\n      throw new CoercingParseLiteralException(\r\n          \"Try something like '\"\r\n              + java.time.LocalDateTime.now().truncatedTo(ChronoUnit.MINUTES).plusDays(1)\r\n              + \"' instead.\",\r\n          e);\r\n    }\r\n  }\r\n\r\n  public static final GraphQLScalarType LocalDateTime =\r\n      GraphQLScalarType.newScalar()\r\n          .name(\"LocalDateTime\")\r\n          .description(\"A custom scalar that handles timestamps that exclude timezone information\")\r\n          .coercing(\r\n              new Coercing\u003cjava.time.LocalDateTime, String\u003e() {\r\n                @Override\r\n                public String serialize(Object dataFetcherResult) {\r\n                  return null; // omitted as its not relevant to this issue\r\n                }\r\n\r\n                @Override\r\n                public java.time.LocalDateTime parseValue(Object input) {\r\n                  return parseLocalDateTimeValue(input);\r\n                }\r\n\r\n                @Override\r\n                public java.time.LocalDateTime parseLiteral(Object input) {\r\n                  return parseLocalDateTimeLiteral(input);\r\n                }\r\n              })\r\n          .build();\r\n```\r\n\r\n\r\n\r\n","author":{"url":"https://github.com/softprops","@type":"Person","name":"softprops"},"datePublished":"2022-04-23T21:34:07.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/2811/graphql-java/issues/2811"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:5de8040d-74ca-f703-38da-c7172622207a
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idDC46:2E5AC3:14ECCA:1C4080:6A5FE951
html-safe-nonce6397a55cdec33bc901658ea8d9d27a896c2765dec9ee3613a93b3a004a419e20
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQzQ2OjJFNUFDMzoxNEVDQ0E6MUM0MDgwOjZBNUZFOTUxIiwidmlzaXRvcl9pZCI6IjMxNDg2NTQxODQ0NzgyNzE4MjUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac5ef14bf8225f27b38345d8379c23131e0d4dca85a6a68ff24f7d158d78d6c107
hovercard-subject-tagissue:1213459314
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/graphql-java/graphql-java/2811/issue_layout
twitter:imagehttps://opengraph.githubassets.com/6ded063b8e45a6e1cec4a4fafb588fb00d375ba455aabc616e1b2be6374b27c1/graphql-java/graphql-java/issues/2811
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/6ded063b8e45a6e1cec4a4fafb588fb00d375ba455aabc616e1b2be6374b27c1/graphql-java/graphql-java/issues/2811
og:image:altDescribe the bug I've recently noticed a difference in behavior (using release 18.0) between how exceptions are handled implementing a custom scalar which parses input fields values and literals. A...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamesoftprops
hostnamegithub.com
expected-hostnamegithub.com
Noneba296ecd3a3521238fe43b3b3b08cc09207ddc21173e16ee656db03803de8e2b
turbo-cache-controlno-preview
go-importgithub.com/graphql-java/graphql-java git https://github.com/graphql-java/graphql-java.git
octolytics-dimension-user_id14289921
octolytics-dimension-user_logingraphql-java
octolytics-dimension-repository_id38602457
octolytics-dimension-repository_nwographql-java/graphql-java
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id38602457
octolytics-dimension-repository_network_root_nwographql-java/graphql-java
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release6e50fb37e29e4aa0df6386cb485e58b0e3ca97ab
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/graphql-java/graphql-java/issues/2811#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgraphql-java%2Fgraphql-java%2Fissues%2F2811
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
Code QualityEnforce quality at mergehttps://github.com/features/code-quality
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgraphql-java%2Fgraphql-java%2Fissues%2F2811
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=graphql-java%2Fgraphql-java
Reloadhttps://github.com/graphql-java/graphql-java/issues/2811
Reloadhttps://github.com/graphql-java/graphql-java/issues/2811
Reloadhttps://github.com/graphql-java/graphql-java/issues/2811
Please reload this pagehttps://github.com/graphql-java/graphql-java/issues/2811
graphql-java https://github.com/graphql-java
graphql-javahttps://github.com/graphql-java/graphql-java
Notifications https://github.com/login?return_to=%2Fgraphql-java%2Fgraphql-java
Fork 1.1k https://github.com/login?return_to=%2Fgraphql-java%2Fgraphql-java
Star 6.2k https://github.com/login?return_to=%2Fgraphql-java%2Fgraphql-java
Code https://github.com/graphql-java/graphql-java
Issues 26 https://github.com/graphql-java/graphql-java/issues
Pull requests 12 https://github.com/graphql-java/graphql-java/pulls
Discussions https://github.com/graphql-java/graphql-java/discussions
Actions https://github.com/graphql-java/graphql-java/actions
Projects https://github.com/graphql-java/graphql-java/projects
Wiki https://github.com/graphql-java/graphql-java/wiki
Security and quality 0 https://github.com/graphql-java/graphql-java/security
Insights https://github.com/graphql-java/graphql-java/pulse
Code https://github.com/graphql-java/graphql-java
Issues https://github.com/graphql-java/graphql-java/issues
Pull requests https://github.com/graphql-java/graphql-java/pulls
Discussions https://github.com/graphql-java/graphql-java/discussions
Actions https://github.com/graphql-java/graphql-java/actions
Projects https://github.com/graphql-java/graphql-java/projects
Wiki https://github.com/graphql-java/graphql-java/wiki
Security and quality https://github.com/graphql-java/graphql-java/security
Insights https://github.com/graphql-java/graphql-java/pulse
Difference in catch and reporting behavior of Coercing value errors vs literal errorshttps://github.com/graphql-java/graphql-java/issues/2811#top
https://github.com/softprops
softpropshttps://github.com/softprops
on Apr 23, 2022https://github.com/graphql-java/graphql-java/issues/2811#issue-1213459314
as described in the docshttps://www.graphql-java.com/documentation/scalars/
as described in the docshttps://www.graphql-java.com/documentation/scalars/
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.