diff --git a/main/src/com/google/refine/ProjectMetadata.java b/main/src/com/google/refine/ProjectMetadata.java index d36ca4228..b1ce74fb8 100644 --- a/main/src/com/google/refine/ProjectMetadata.java +++ b/main/src/com/google/refine/ProjectMetadata.java @@ -105,7 +105,7 @@ public class ProjectMetadata implements Jsonizable { writer.endObject(); } - public void write(JSONWriter jsonWriter) throws Exception { + public void write(JSONWriter jsonWriter) throws JSONException { Properties options = new Properties(); options.setProperty("mode", "save"); diff --git a/main/src/com/google/refine/io/FileProjectManager.java b/main/src/com/google/refine/io/FileProjectManager.java index 4cbbc9f89..472c1df2d 100644 --- a/main/src/com/google/refine/io/FileProjectManager.java +++ b/main/src/com/google/refine/io/FileProjectManager.java @@ -231,6 +231,9 @@ public class FileProjectManager extends ProjectManager { /** * Save the workspace's data out to file in a safe way: save to a temporary file first * and rename it to the real file. + *

+ * FIXME: Even though this attempts to be safe by writing new file and renaming, + * it's still possible for it to corrupt things. */ @Override protected void saveWorkspace() { @@ -273,11 +276,7 @@ public class FileProjectManager extends ProjectManager { if (metadata != null) { jsonWriter.value(id); - try { - ProjectMetadataUtilities.save(metadata, getProjectDir(id)); - } catch (Exception e) { - e.printStackTrace(); - } + ProjectMetadataUtilities.save(metadata, getProjectDir(id)); } } jsonWriter.endArray(); diff --git a/main/src/com/google/refine/io/ProjectMetadataUtilities.java b/main/src/com/google/refine/io/ProjectMetadataUtilities.java index 46180feae..49d376bf9 100644 --- a/main/src/com/google/refine/io/ProjectMetadataUtilities.java +++ b/main/src/com/google/refine/io/ProjectMetadataUtilities.java @@ -36,9 +36,11 @@ package com.google.refine.io; import java.io.File; import java.io.FileOutputStream; import java.io.FileReader; +import java.io.IOException; import java.io.OutputStreamWriter; import java.io.Writer; +import org.json.JSONException; import org.json.JSONObject; import org.json.JSONTokener; import org.json.JSONWriter; @@ -51,16 +53,9 @@ import com.google.refine.ProjectMetadata; public class ProjectMetadataUtilities { final static Logger logger = LoggerFactory.getLogger("project_metadata_utilities"); - public static void save(ProjectMetadata projectMeta, File projectDir) throws Exception { + public static void save(ProjectMetadata projectMeta, File projectDir) throws JSONException, IOException { File tempFile = new File(projectDir, "metadata.temp.json"); - try { - saveToFile(projectMeta, tempFile); - } catch (Exception e) { - e.printStackTrace(); - - logger.warn("Failed to save project metadata"); - return; - } + saveToFile(projectMeta, tempFile); File file = new File(projectDir, "metadata.json"); File oldFile = new File(projectDir, "metadata.old.json"); @@ -75,7 +70,7 @@ public class ProjectMetadataUtilities { } } - protected static void saveToFile(ProjectMetadata projectMeta, File metadataFile) throws Exception { + protected static void saveToFile(ProjectMetadata projectMeta, File metadataFile) throws JSONException, IOException { Writer writer = new OutputStreamWriter(new FileOutputStream(metadataFile)); try { JSONWriter jsonWriter = new JSONWriter(writer);