@@ -49,12 +49,10 @@ public static JsonElement getJson(AdvancementHolder holder, AdvancementTree tree
4949 }
5050 try {
5151 return Advancement .CODEC .encodeStart (JsonOps .INSTANCE , builder .build (holder .id ()).value ()).getOrThrow ();
52- } catch (IllegalStateException e ) {
53- AdvancementHelper .LOGGER .error ("Failed to encode the advancement {}" , holder .id ());
54- AdvancementHelper .LOGGER .error (e .getMessage ());
55- JsonObject fail = new JsonObject ();
56- fail .addProperty ("error" , e .getMessage ());
57- return fail ;
52+ } catch (IllegalStateException | IllegalArgumentException e ) {
53+ return error (e , "Failed to encode the advancement {}!" , holder .id ().toString ());
54+ } catch (Exception e ){
55+ return error (e , "Failed to encode the advancement {} due to an unexpected error!" , holder .id ().toString ());
5856 }
5957 }
6058
@@ -72,12 +70,18 @@ public static JsonElement getJson(AdvancementProgress progress) {
7270 result .add ("remaining" , remaining );
7371 result .addProperty ("done_percent" , progress .getPercent ());
7472 return result ;
75- } catch (IllegalStateException e ) {
76- AdvancementHelper .LOGGER .error ("Failed to encode the progress of the advancement {}" , progress .toString ());
77- AdvancementHelper .LOGGER .error (e .getMessage ());
78- JsonObject fail = new JsonObject ();
79- fail .addProperty ("error" , e .getMessage ());
80- return fail ;
73+ } catch (IllegalStateException | IllegalArgumentException e ) {
74+ return error (e , "Failed to encode the progress of the advancement {}!" , progress .toString ());
75+ } catch (Exception e ){
76+ return error (e , "Failed to encode the progress of the advancement {} due to an unexpected error!" , progress .toString ());
8177 }
8278 }
79+
80+ private static JsonElement error (Exception exception , String str1 , String str2 ) {
81+ AdvancementHelper .LOGGER .error (str1 , str2 );
82+ AdvancementHelper .LOGGER .error (exception .getMessage ());
83+ JsonObject fail = new JsonObject ();
84+ fail .addProperty ("error" , exception .getMessage ());
85+ return fail ;
86+ }
8387}
0 commit comments