KubeJS

KubeJS

69M Downloads

Catching of exceptions from RecipeComponent#read causes errors from StringComponent#DYNAMIC to be lost to scripters

ChiefArug opened this issue ยท 1 comments

commented

Minecraft Version

1.20.1

KubeJS Version

kubejs-forge-2001.6.4-build.114.jar

Rhino Version

rhino-forge-2001.2.2-build.18.jar

Architectury Version

architectury-9.1.12-forge.jar

Forge/Fabric Version

47.2.17

Describe your issue

The try/catch here:

try {
return key.component.read(recipe, o);
} catch (Throwable ex) {
throw new RecipeExceptionJS("Unable to cast '" + key + "' value '" + o + "' to '" + key.component.componentType() + "'!", ex);
}
causes errors thrown here:
if (!predicate.test(str)) {
if (error.isEmpty()) {
throw new IllegalArgumentException("Invalid string '" + str + "'");
} else {
throw new IllegalArgumentException("Invalid string '" + str + "': " + error);
}
}
to be caught and not displayed to the scripter because KubeJS doesnt print inner exceptions to the script logs.
Instead an error like ! example.js#2: Failed to create recipe for type 'eidolon:worktable': Unable to cast 'reagents:string' value 'SBB' to 'string'! shows up.

Test case (requires Eidolon: Rebrewed):

//type: startup
const $RecipeSchema = Java.loadClass('dev.latvian.mods.kubejs.recipe.schema.RecipeSchema')
const $ShapedRecipeSchema = Java.loadClass('dev.latvian.mods.kubejs.recipe.schema.minecraft.ShapedRecipeSchema')

StartupEvents.recipeSchemaRegistry(event => {
    const Components = event.components

    let worktableSchema = new $RecipeSchema(
        $ShapedRecipeSchema.RESULT,
        $ShapedRecipeSchema.PATTERN,
        Components.get('filteredString')
            ({ error: "reagents must have a length of four", filter: s => s.length == 4})
            .key('reagents'),
        $ShapedRecipeSchema.KEY
    )

    event.register('eidolon:worktable', worktableSchema);
})
//type: server
ServerEvents.recipes(event => {
    event.recipes.eidolon.worktable('apple', [
        ' R ',
        'RPR',
        ' R '
    ], 'SBB', {
        S: 'wheat_seeds',
        B: 'bone_meal',
        R: 'red_dye',
        P: 'potato'
    });
})

The error here is that the reagents string (the SBB in the middle) must be of length four, but it shows up as a 'cannot cast' error, not the custom error message.

Crash report/logs

No response

commented

Fixed by printing the cause in RecipeExceptionJS as well