From bc7500f33ad996ee8016f59b3a5d7e188eb49319 Mon Sep 17 00:00:00 2001 From: dugenkui03 Date: Thu, 24 Feb 2022 01:58:45 +0800 Subject: [PATCH] Provide location information for missing/invalid schema resources This commit ensures that the `Resource` description is provided when a schema resource is missing, cannot be read, or is invalid. This is useful when the application holds multiple schema files and an error is thrown because of a particular file. Close gh-307 --- .../graphql/execution/DefaultGraphQlSourceBuilder.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/spring-graphql/src/main/java/org/springframework/graphql/execution/DefaultGraphQlSourceBuilder.java b/spring-graphql/src/main/java/org/springframework/graphql/execution/DefaultGraphQlSourceBuilder.java index b553eb3c..62dc4884 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/execution/DefaultGraphQlSourceBuilder.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/execution/DefaultGraphQlSourceBuilder.java @@ -184,7 +184,7 @@ class DefaultGraphQlSourceBuilder implements GraphQlSource.Builder { private TypeDefinitionRegistry parseSchemaResource(Resource schemaResource) { Assert.notNull(schemaResource, "'schemaResource' not provided"); - Assert.isTrue(schemaResource.exists(), "'schemaResource' does not exist"); + Assert.isTrue(schemaResource.exists(), "'schemaResource' must exist: " + schemaResource); try { try (InputStream inputStream = schemaResource.getInputStream()) { return new SchemaParser().parse(inputStream); @@ -193,6 +193,9 @@ class DefaultGraphQlSourceBuilder implements GraphQlSource.Builder { catch (IOException ex) { throw new IllegalArgumentException("Failed to load schema resource: " + schemaResource); } + catch (Exception ex) { + throw new IllegalStateException("Failed to parse schema resource: " + schemaResource, ex); + } } private GraphQLSchema applyTypeVisitors(GraphQLSchema schema) {