From cdf4ae1af7ae195a6de519bbe242c4fe972a8402 Mon Sep 17 00:00:00 2001 From: Dave Date: Mon, 1 Jul 2024 16:37:50 +0200 Subject: [PATCH] v3.12 dev. progress A prototype error handler for quick-share `Exception`s, but messy and lacks descriptive explanations of errors that take place. --- .../gui/screen/QuickShareDownloadScreen.java | 14 +++++++++++--- .../client/gui/screen/QuickShareUploadScreen.java | 13 +++++++++++-- .../gui/screen/QuickShareDownloadScreen.java | 14 +++++++++++--- .../client/gui/screen/QuickShareUploadScreen.java | 13 +++++++++++-- 4 files changed, 44 insertions(+), 10 deletions(-) diff --git a/betterstats-3-fabric-1.20.5/src/main/java/io/github/thecsdev/betterstats/client/gui/screen/QuickShareDownloadScreen.java b/betterstats-3-fabric-1.20.5/src/main/java/io/github/thecsdev/betterstats/client/gui/screen/QuickShareDownloadScreen.java index b20bebd..a15d8e4 100644 --- a/betterstats-3-fabric-1.20.5/src/main/java/io/github/thecsdev/betterstats/client/gui/screen/QuickShareDownloadScreen.java +++ b/betterstats-3-fabric-1.20.5/src/main/java/io/github/thecsdev/betterstats/client/gui/screen/QuickShareDownloadScreen.java @@ -28,6 +28,7 @@ import io.github.thecsdev.betterstats.util.BST; import io.github.thecsdev.betterstats.util.io.BetterStatsWebApiUtils; import io.github.thecsdev.tcdcommons.api.client.gui.other.TLabelElement; +import io.github.thecsdev.tcdcommons.api.client.gui.screen.TStackTraceScreen; import io.github.thecsdev.tcdcommons.api.util.enumerations.HorizontalAlignment; import io.github.thecsdev.tcdcommons.api.util.io.HttpUtils.FetchOptions; import io.github.thecsdev.tcdcommons.api.util.io.cache.CachedResource; @@ -87,9 +88,13 @@ public QuickShareDownloadScreen(@Nullable Screen bssParent, @Nullable Screen par { this.__stage = -1; this.__error = exception; - new Exception("Failed to retrieve a quick-shared MCBS file '" + - this.quickShareCode + "'", exception).printStackTrace(); - refresh(); + if(!isOpen()) return; //break the operation if the user closed the screen + + final var exc = new Exception("Failed to download a quick-shared MCBS file '" + + this.quickShareCode + "'", exception); + exc.printStackTrace(); + MC_CLIENT.setScreen(new TStackTraceScreen(getParentScreen(), exc).getAsScreen()); + //refresh(); } // -------------------------------------------------- private @Internal void __start__stage1() @@ -98,6 +103,7 @@ public QuickShareDownloadScreen(@Nullable Screen bssParent, @Nullable Screen par if(this.__started) return; this.__started = true; this.__stage = 1; + if(!isOpen()) return; //break the operation if the user closed the screen //note: do not call `refresh()` here //fetch the API links @@ -110,6 +116,7 @@ public QuickShareDownloadScreen(@Nullable Screen bssParent, @Nullable Screen par { //prepare this.__stage = 2; + if(!isOpen()) return; //break the operation if the user closed the screen refresh(); //parse the user-input identifier @@ -259,6 +266,7 @@ else if(du_ready.get() == null) private @Internal void __start__stage4(final byte[] mcbs) { this.__stage = 4; + if(!isOpen()) return; //break the operation if the user closed the screen refresh(); try { diff --git a/betterstats-3-fabric-1.20.5/src/main/java/io/github/thecsdev/betterstats/client/gui/screen/QuickShareUploadScreen.java b/betterstats-3-fabric-1.20.5/src/main/java/io/github/thecsdev/betterstats/client/gui/screen/QuickShareUploadScreen.java index 60b6c2f..1ec5c6c 100644 --- a/betterstats-3-fabric-1.20.5/src/main/java/io/github/thecsdev/betterstats/client/gui/screen/QuickShareUploadScreen.java +++ b/betterstats-3-fabric-1.20.5/src/main/java/io/github/thecsdev/betterstats/client/gui/screen/QuickShareUploadScreen.java @@ -34,6 +34,7 @@ import io.github.thecsdev.betterstats.util.BST; import io.github.thecsdev.betterstats.util.io.BetterStatsWebApiUtils; import io.github.thecsdev.tcdcommons.api.client.gui.other.TLabelElement; +import io.github.thecsdev.tcdcommons.api.client.gui.screen.TStackTraceScreen; import io.github.thecsdev.tcdcommons.api.client.gui.widget.TButtonWidget; import io.github.thecsdev.tcdcommons.api.util.enumerations.HorizontalAlignment; import io.github.thecsdev.tcdcommons.api.util.io.HttpUtils.FetchOptions; @@ -106,8 +107,12 @@ public QuickShareUploadScreen(@Nullable Screen parent, IStatsProvider stats) { this.__stage = -1; this.__error = exception; - new Exception("Failed to quick-share an MCBS file.", exception).printStackTrace(); - refresh(); + if(!isOpen()) return; //break the operation if the user closed the screen + + final var exc = new Exception("Failed to quick-share an MCBS file.", exception); + exc.printStackTrace(); + MC_CLIENT.setScreen(new TStackTraceScreen(getParentScreen(), exc).getAsScreen()); + //refresh(); } // -------------------------------------------------- private @Internal void __start__stage1() @@ -116,6 +121,7 @@ public QuickShareUploadScreen(@Nullable Screen parent, IStatsProvider stats) if(this.__started) return; this.__started = true; this.__stage = 1; + if(!isOpen()) return; //break the operation if the user closed the screen //note: do not call `refresh()` here //fetch the API links @@ -128,6 +134,7 @@ public QuickShareUploadScreen(@Nullable Screen parent, IStatsProvider stats) { //prepare this.__stage = 2; + if(!isOpen()) return; //break the operation if the user closed the screen refresh(); //fetch the upload link @@ -186,6 +193,7 @@ public CachedResource fetchResourceSync() throws Exception { //prepare this.__stage = 3; + if(!isOpen()) return; //break the operation if the user closed the screen refresh(); //perform the upload @@ -291,6 +299,7 @@ public CachedResource fetchResourceSync() throws Exception private @Internal void __start__stage4() { this.__stage = 4; + if(!isOpen()) return; //break the operation if the user closed the screen refresh(); } // ================================================== diff --git a/betterstats-3-fabric-1.21/src/main/java/io/github/thecsdev/betterstats/client/gui/screen/QuickShareDownloadScreen.java b/betterstats-3-fabric-1.21/src/main/java/io/github/thecsdev/betterstats/client/gui/screen/QuickShareDownloadScreen.java index b20bebd..a15d8e4 100644 --- a/betterstats-3-fabric-1.21/src/main/java/io/github/thecsdev/betterstats/client/gui/screen/QuickShareDownloadScreen.java +++ b/betterstats-3-fabric-1.21/src/main/java/io/github/thecsdev/betterstats/client/gui/screen/QuickShareDownloadScreen.java @@ -28,6 +28,7 @@ import io.github.thecsdev.betterstats.util.BST; import io.github.thecsdev.betterstats.util.io.BetterStatsWebApiUtils; import io.github.thecsdev.tcdcommons.api.client.gui.other.TLabelElement; +import io.github.thecsdev.tcdcommons.api.client.gui.screen.TStackTraceScreen; import io.github.thecsdev.tcdcommons.api.util.enumerations.HorizontalAlignment; import io.github.thecsdev.tcdcommons.api.util.io.HttpUtils.FetchOptions; import io.github.thecsdev.tcdcommons.api.util.io.cache.CachedResource; @@ -87,9 +88,13 @@ public QuickShareDownloadScreen(@Nullable Screen bssParent, @Nullable Screen par { this.__stage = -1; this.__error = exception; - new Exception("Failed to retrieve a quick-shared MCBS file '" + - this.quickShareCode + "'", exception).printStackTrace(); - refresh(); + if(!isOpen()) return; //break the operation if the user closed the screen + + final var exc = new Exception("Failed to download a quick-shared MCBS file '" + + this.quickShareCode + "'", exception); + exc.printStackTrace(); + MC_CLIENT.setScreen(new TStackTraceScreen(getParentScreen(), exc).getAsScreen()); + //refresh(); } // -------------------------------------------------- private @Internal void __start__stage1() @@ -98,6 +103,7 @@ public QuickShareDownloadScreen(@Nullable Screen bssParent, @Nullable Screen par if(this.__started) return; this.__started = true; this.__stage = 1; + if(!isOpen()) return; //break the operation if the user closed the screen //note: do not call `refresh()` here //fetch the API links @@ -110,6 +116,7 @@ public QuickShareDownloadScreen(@Nullable Screen bssParent, @Nullable Screen par { //prepare this.__stage = 2; + if(!isOpen()) return; //break the operation if the user closed the screen refresh(); //parse the user-input identifier @@ -259,6 +266,7 @@ else if(du_ready.get() == null) private @Internal void __start__stage4(final byte[] mcbs) { this.__stage = 4; + if(!isOpen()) return; //break the operation if the user closed the screen refresh(); try { diff --git a/betterstats-3-fabric-1.21/src/main/java/io/github/thecsdev/betterstats/client/gui/screen/QuickShareUploadScreen.java b/betterstats-3-fabric-1.21/src/main/java/io/github/thecsdev/betterstats/client/gui/screen/QuickShareUploadScreen.java index 60b6c2f..1ec5c6c 100644 --- a/betterstats-3-fabric-1.21/src/main/java/io/github/thecsdev/betterstats/client/gui/screen/QuickShareUploadScreen.java +++ b/betterstats-3-fabric-1.21/src/main/java/io/github/thecsdev/betterstats/client/gui/screen/QuickShareUploadScreen.java @@ -34,6 +34,7 @@ import io.github.thecsdev.betterstats.util.BST; import io.github.thecsdev.betterstats.util.io.BetterStatsWebApiUtils; import io.github.thecsdev.tcdcommons.api.client.gui.other.TLabelElement; +import io.github.thecsdev.tcdcommons.api.client.gui.screen.TStackTraceScreen; import io.github.thecsdev.tcdcommons.api.client.gui.widget.TButtonWidget; import io.github.thecsdev.tcdcommons.api.util.enumerations.HorizontalAlignment; import io.github.thecsdev.tcdcommons.api.util.io.HttpUtils.FetchOptions; @@ -106,8 +107,12 @@ public QuickShareUploadScreen(@Nullable Screen parent, IStatsProvider stats) { this.__stage = -1; this.__error = exception; - new Exception("Failed to quick-share an MCBS file.", exception).printStackTrace(); - refresh(); + if(!isOpen()) return; //break the operation if the user closed the screen + + final var exc = new Exception("Failed to quick-share an MCBS file.", exception); + exc.printStackTrace(); + MC_CLIENT.setScreen(new TStackTraceScreen(getParentScreen(), exc).getAsScreen()); + //refresh(); } // -------------------------------------------------- private @Internal void __start__stage1() @@ -116,6 +121,7 @@ public QuickShareUploadScreen(@Nullable Screen parent, IStatsProvider stats) if(this.__started) return; this.__started = true; this.__stage = 1; + if(!isOpen()) return; //break the operation if the user closed the screen //note: do not call `refresh()` here //fetch the API links @@ -128,6 +134,7 @@ public QuickShareUploadScreen(@Nullable Screen parent, IStatsProvider stats) { //prepare this.__stage = 2; + if(!isOpen()) return; //break the operation if the user closed the screen refresh(); //fetch the upload link @@ -186,6 +193,7 @@ public CachedResource fetchResourceSync() throws Exception { //prepare this.__stage = 3; + if(!isOpen()) return; //break the operation if the user closed the screen refresh(); //perform the upload @@ -291,6 +299,7 @@ public CachedResource fetchResourceSync() throws Exception private @Internal void __start__stage4() { this.__stage = 4; + if(!isOpen()) return; //break the operation if the user closed the screen refresh(); } // ==================================================