Skip to content

Commit

Permalink
v3.12 dev. progress
Browse files Browse the repository at this point in the history
A prototype error handler for quick-share `Exception`s, but messy and lacks descriptive explanations of errors that take place.
  • Loading branch information
TheCSDev committed Jul 1, 2024
1 parent f7da850 commit cdf4ae1
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -186,6 +193,7 @@ public CachedResource<JsonObject> fetchResourceSync() throws Exception
{
//prepare
this.__stage = 3;
if(!isOpen()) return; //break the operation if the user closed the screen
refresh();

//perform the upload
Expand Down Expand Up @@ -291,6 +299,7 @@ public CachedResource<String> fetchResourceSync() throws Exception
private @Internal void __start__stage4()
{
this.__stage = 4;
if(!isOpen()) return; //break the operation if the user closed the screen
refresh();
}
// ==================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -186,6 +193,7 @@ public CachedResource<JsonObject> fetchResourceSync() throws Exception
{
//prepare
this.__stage = 3;
if(!isOpen()) return; //break the operation if the user closed the screen
refresh();

//perform the upload
Expand Down Expand Up @@ -291,6 +299,7 @@ public CachedResource<String> fetchResourceSync() throws Exception
private @Internal void __start__stage4()
{
this.__stage = 4;
if(!isOpen()) return; //break the operation if the user closed the screen
refresh();
}
// ==================================================
Expand Down

0 comments on commit cdf4ae1

Please sign in to comment.