From a9e52ade68ad69611271d293f6fe79463e8b75ba Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Thu, 28 May 2026 16:13:11 +0200 Subject: [PATCH] Resilient flatten: catch exceptions + return meaningful error messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Wrap flattenSingleDir in try-catch — if it fails, the upload continues and the cd fix in dosbox.conf handles subdirectory executables - Add global catch to upload method returning the actual exception message instead of a generic 500 - This will help diagnose why the user's King's Quest VI zip fails: flattening can throw on special filenames, Mac resource forks, symlinks, or other unusual ZIP contents --- src/main/java/com/dostalgia/UploadResource.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/dostalgia/UploadResource.java b/src/main/java/com/dostalgia/UploadResource.java index 7caae84..a7876a8 100644 --- a/src/main/java/com/dostalgia/UploadResource.java +++ b/src/main/java/com/dostalgia/UploadResource.java @@ -64,7 +64,12 @@ public class UploadResource { Path extractDir = tmpDir.resolve("extracted"); unzip(zipPath, extractDir); // If the ZIP has a single root directory, flatten it - flattenSingleDir(extractDir); + try { + flattenSingleDir(extractDir); + } catch (Exception e) { + LOG.warning("Flatten failed for '" + filename + "': " + e.getMessage() + + " — continuing (cd in autoexec handles subdirs)"); + } // Find main executable String mainExe = findMainExe(extractDir); @@ -120,6 +125,11 @@ public class UploadResource { return Response.status(201).entity(game).build(); + } catch (Exception e) { + LOG.severe("Upload failed for '" + filename + "': " + e.getMessage()); + return Response.serverError() + .entity(Map.of("error", "Upload failed: " + e.getMessage())) + .build(); } finally { deleteDir(tmpDir); }