#Creating descriptive parsing errors

1 messages · Page 1 of 1 (latest)

patent locust
#

In my enchantment plugin the parsing system is a multi-step process that goes somewhat like the following:
enchantment:
single level:
single effect

A parsing issue could occur at any of these steps. My current idea is to throw an exception when an issue occurs and then catch it, add additional context, and then re-throw it in each higher parsing step until it gets to the top, where it will be shown in console.

The problem is catching and rethrowing an exception several times feels a bit janky, but I can't really think of a better idea at the moment.

#

I guess I could pass a List<String> through the parsing process and add any errors to that to then show that list in console

#

Sample output for an error would be something like the following:

Error parsing enchantment test:
Error parsing level 1:
Error parsing effect "damage":
The damage amount must be greater than 0, found -1

lavish drift
#

Do you need to catch them all at once? You could always start from the top, throw that, and once they fix it, then throw the next error

patent locust
lavish drift
#

Ah.

Well I don't think you'd necessarily have to "rethrow" them in higher parsing steps.

If you do the parsing from top to bottom (so starting from the enchantment and ending at the effect), and for example, an error is thrown in the effect, you already know what the enchantment and levels are, so you can just add those into your error

patent locust
#

Yeah I guess I could just pass them down