diff --git a/src/main/java/de/marhali/easyi18n/io/IOHandler.java b/src/main/java/de/marhali/easyi18n/io/IOHandler.java
index 6e1a73b..1ee97da 100644
--- a/src/main/java/de/marhali/easyi18n/io/IOHandler.java
+++ b/src/main/java/de/marhali/easyi18n/io/IOHandler.java
@@ -1,6 +1,5 @@
package de.marhali.easyi18n.io;
-import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
@@ -12,6 +11,7 @@ import de.marhali.easyi18n.model.*;
import org.jetbrains.annotations.NotNull;
import java.io.File;
+import java.io.IOException;
import java.util.List;
/**
@@ -37,18 +37,15 @@ public class IOHandler {
this.parserStrategyType = settings.getParserStrategy();
this.parserStrategy = parserStrategyType.getStrategy()
.getDeclaredConstructor(SettingsState.class).newInstance(settings);
-
- Logger.getInstance(IOHandler.class).debug("Using: ",
- settings.getFolderStrategy(), settings.getParserStrategy(), settings.getFilePattern());
}
/**
* Reads translation files from the local project into our data structure.
* Note: This method needs to be called from a Read-Action-Context (see ApplicationManager)
* @return Translation data based on the configured strategies
- * @throws Exception Could not read translation data
+ * @throws IOException Could not read translation data
*/
- public @NotNull TranslationData read() throws Exception {
+ public @NotNull TranslationData read() throws IOException {
String localesPath = this.settings.getLocalesPath();
if(localesPath == null || localesPath.isEmpty()) {
@@ -65,7 +62,11 @@ public class IOHandler {
List translationFiles = this.folderStrategy.analyzeFolderStructure(localesDirectory);
for(TranslationFile file : translationFiles) {
- this.parserStrategy.read(file, data);
+ try {
+ this.parserStrategy.read(file, data);
+ } catch(Exception ex) {
+ throw new IOException(file + "\n\n" + ex.getMessage(), ex);
+ }
}
return data;
@@ -75,9 +76,9 @@ public class IOHandler {
* Writes the provided translation data to the local project files
* Note: This method must be called from an Write-Action-Context (see ApplicationManager)
* @param data Cached translation data to save
- * @throws Exception Write action failed
+ * @throws IOException Write action failed
*/
- public void write(@NotNull TranslationData data) throws Exception {
+ public void write(@NotNull TranslationData data) throws IOException {
String localesPath = this.settings.getLocalesPath();
if(localesPath == null || localesPath.isEmpty()) {
@@ -88,7 +89,11 @@ public class IOHandler {
this.folderStrategy.constructFolderStructure(localesPath, this.parserStrategyType, data);
for(TranslationFile file : translationFiles) {
- this.parserStrategy.write(data, file);
+ try {
+ this.parserStrategy.write(data, file);
+ } catch (Exception ex) {
+ throw new IOException(file + "\n\n" + ex.getMessage(), ex);
+ }
}
}
}
diff --git a/src/main/java/de/marhali/easyi18n/io/parser/ParserStrategy.java b/src/main/java/de/marhali/easyi18n/io/parser/ParserStrategy.java
index 87da0e4..1678569 100644
--- a/src/main/java/de/marhali/easyi18n/io/parser/ParserStrategy.java
+++ b/src/main/java/de/marhali/easyi18n/io/parser/ParserStrategy.java
@@ -4,7 +4,6 @@ import de.marhali.easyi18n.model.*;
import org.jetbrains.annotations.NotNull;
-import java.io.IOException;
import java.util.Objects;
/**
@@ -24,14 +23,14 @@ public abstract class ParserStrategy {
* @param file File to read from
* @param data Target translation data to save the parsed data
*/
- public abstract void read(@NotNull TranslationFile file, @NotNull TranslationData data) throws IOException;
+ public abstract void read(@NotNull TranslationFile file, @NotNull TranslationData data) throws Exception;
/**
* Writes the relevant data to the translation file (consider namespace and locale)
* @param data Translation data cache
* @param file Target translation file
*/
- public abstract void write(@NotNull TranslationData data, @NotNull TranslationFile file) throws IOException;
+ public abstract void write(@NotNull TranslationData data, @NotNull TranslationFile file) throws Exception;
/**
* Determines translation node to use for parsing
diff --git a/src/main/java/de/marhali/easyi18n/io/parser/json/JsonParserStrategy.java b/src/main/java/de/marhali/easyi18n/io/parser/json/JsonParserStrategy.java
index 6511c1b..a765547 100644
--- a/src/main/java/de/marhali/easyi18n/io/parser/json/JsonParserStrategy.java
+++ b/src/main/java/de/marhali/easyi18n/io/parser/json/JsonParserStrategy.java
@@ -28,7 +28,7 @@ public class JsonParserStrategy extends ParserStrategy {
}
@Override
- public void read(@NotNull TranslationFile file, @NotNull TranslationData data) throws IOException {
+ public void read(@NotNull TranslationFile file, @NotNull TranslationData data) throws Exception {
data.addLocale(file.getLocale());
VirtualFile vf = file.getVirtualFile();
@@ -43,7 +43,7 @@ public class JsonParserStrategy extends ParserStrategy {
}
@Override
- public void write(@NotNull TranslationData data, @NotNull TranslationFile file) throws IOException {
+ public void write(@NotNull TranslationData data, @NotNull TranslationFile file) throws Exception {
TranslationNode targetNode = super.getTargetNode(data, file);
JsonObject output = new JsonObject();
diff --git a/src/main/java/de/marhali/easyi18n/io/parser/properties/PropertiesParserStrategy.java b/src/main/java/de/marhali/easyi18n/io/parser/properties/PropertiesParserStrategy.java
index 61b0257..35a45db 100644
--- a/src/main/java/de/marhali/easyi18n/io/parser/properties/PropertiesParserStrategy.java
+++ b/src/main/java/de/marhali/easyi18n/io/parser/properties/PropertiesParserStrategy.java
@@ -10,7 +10,6 @@ import de.marhali.easyi18n.model.TranslationNode;
import org.jetbrains.annotations.NotNull;
-import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringWriter;
@@ -26,7 +25,7 @@ public class PropertiesParserStrategy extends ParserStrategy {
}
@Override
- public void read(@NotNull TranslationFile file, @NotNull TranslationData data) throws IOException {
+ public void read(@NotNull TranslationFile file, @NotNull TranslationData data) throws Exception {
data.addLocale(file.getLocale());
VirtualFile vf = file.getVirtualFile();
@@ -41,7 +40,7 @@ public class PropertiesParserStrategy extends ParserStrategy {
}
@Override
- public void write(@NotNull TranslationData data, @NotNull TranslationFile file) throws IOException {
+ public void write(@NotNull TranslationData data, @NotNull TranslationFile file) throws Exception {
TranslationNode targetNode = super.getTargetNode(data, file);
TranslationData targetData = new TranslationData(data.getLocales(), targetNode);
diff --git a/src/main/java/de/marhali/easyi18n/io/parser/yaml/YamlParserStrategy.java b/src/main/java/de/marhali/easyi18n/io/parser/yaml/YamlParserStrategy.java
index bca8478..dddf5ec 100644
--- a/src/main/java/de/marhali/easyi18n/io/parser/yaml/YamlParserStrategy.java
+++ b/src/main/java/de/marhali/easyi18n/io/parser/yaml/YamlParserStrategy.java
@@ -9,10 +9,10 @@ import de.marhali.easyi18n.model.TranslationFile;
import de.marhali.easyi18n.model.TranslationNode;
import org.jetbrains.annotations.NotNull;
+
import thito.nodeflow.config.MapSection;
import thito.nodeflow.config.Section;
-import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
@@ -27,7 +27,7 @@ public class YamlParserStrategy extends ParserStrategy {
}
@Override
- public void read(@NotNull TranslationFile file, @NotNull TranslationData data) throws IOException {
+ public void read(@NotNull TranslationFile file, @NotNull TranslationData data) throws Exception {
data.addLocale(file.getLocale());
VirtualFile vf = file.getVirtualFile();
@@ -40,7 +40,7 @@ public class YamlParserStrategy extends ParserStrategy {
}
@Override
- public void write(@NotNull TranslationData data, @NotNull TranslationFile file) throws IOException {
+ public void write(@NotNull TranslationData data, @NotNull TranslationFile file) throws Exception {
TranslationNode targetNode = super.getTargetNode(data, file);
Section output = new MapSection();