diff --git a/json/jsonSchema/src/com/jetbrains/jsonSchema/JsonSchemaConfigurable.java b/json/jsonSchema/src/com/jetbrains/jsonSchema/JsonSchemaConfigurable.java index 6d354b66d121..4c005900c3f0 100644 --- a/json/jsonSchema/src/com/jetbrains/jsonSchema/JsonSchemaConfigurable.java +++ b/json/jsonSchema/src/com/jetbrains/jsonSchema/JsonSchemaConfigurable.java @@ -7,6 +7,7 @@ import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.CollectConsumer; import com.jetbrains.jsonSchema.impl.JsonSchemaReader; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NotNull; @@ -14,6 +15,7 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.io.File; +import java.io.IOException; /** * @author Irina.Chernushina on 2/2/2016. @@ -97,8 +99,18 @@ public class JsonSchemaConfigurable extends NamedConfigurable collectConsumer = new CollectConsumer<>(); + final File file = new File(myProject.getBasePath(), myView.getSchemaSubPath()); + try { + if (!JsonSchemaReader.isJsonSchema(FileUtil.loadFile(file), collectConsumer)) { + final String message; + if (collectConsumer.getResult().isEmpty()) message = "Can not read JSON schema from file (Unknown reason)"; + else message = "Can not read JSON schema from file: " + StringUtil.join(collectConsumer.getResult(), "; "); + throw new ConfigurationException(message); + } + } + catch (IOException e) { + throw new ConfigurationException("Can not read JSON schema from file: " + e.getMessage()); } } } diff --git a/json/jsonSchema/src/com/jetbrains/jsonSchema/JsonSchemaMappingsConfigurable.java b/json/jsonSchema/src/com/jetbrains/jsonSchema/JsonSchemaMappingsConfigurable.java index 43d3f6ba7039..ce86822a47b3 100644 --- a/json/jsonSchema/src/com/jetbrains/jsonSchema/JsonSchemaMappingsConfigurable.java +++ b/json/jsonSchema/src/com/jetbrains/jsonSchema/JsonSchemaMappingsConfigurable.java @@ -17,6 +17,7 @@ import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.CollectConsumer; import com.intellij.util.IconUtil; import com.jetbrains.jsonSchema.ide.JsonSchemaService; import com.jetbrains.jsonSchema.impl.JsonSchemaReader; @@ -383,8 +384,12 @@ public class JsonSchemaMappingsConfigurable extends MasterDetailsComponent imple myError = "Problem during reading JSON schema from '" + myFile.getName() + "': " + e1.getMessage(); return false; } - if (!JsonSchemaReader.isJsonSchema(myText)) { - myError = "JSON Schema not found in '" + myFile.getName() + "'"; + final CollectConsumer collectConsumer = new CollectConsumer<>(); + if (!JsonSchemaReader.isJsonSchema(myText, collectConsumer)) { + myError = "JSON Schema not found or contain error in '" + myFile.getName() + "'"; + if (!collectConsumer.getResult().isEmpty()) { + myError += ": " + StringUtil.join(collectConsumer.getResult(), "; "); + } return false; } if (!myLoadText) myText = null; diff --git a/json/jsonSchema/src/com/jetbrains/jsonSchema/impl/JsonSchemaReader.java b/json/jsonSchema/src/com/jetbrains/jsonSchema/impl/JsonSchemaReader.java index b1971f568b45..f15efbcd8e0a 100644 --- a/json/jsonSchema/src/com/jetbrains/jsonSchema/impl/JsonSchemaReader.java +++ b/json/jsonSchema/src/com/jetbrains/jsonSchema/impl/JsonSchemaReader.java @@ -4,6 +4,7 @@ import com.google.gson.TypeAdapter; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonToken; import com.google.gson.stream.JsonWriter; +import com.intellij.util.Consumer; import com.intellij.util.ThrowablePairConsumer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -34,13 +35,15 @@ public class JsonSchemaReader { return object; } - public static boolean isJsonSchema(@NotNull final String string) { + public static boolean isJsonSchema(@NotNull final String string, Consumer errorConsumer) { try { new JsonSchemaReader().read(new java.io.StringReader(string)); return true; } catch (IOException e) { + errorConsumer.consume(e.getMessage()); return false; } catch (Exception e) { + errorConsumer.consume(e.getMessage()); return false; } }