Kord-Extensions / kord-extensions

Kord extensions framework, providing commands and distinct units of functionality
https://kordex.dev
European Union Public License 1.2
112 stars 27 forks source link

Detailed description of the error about an unspecified value in the slash command field in the command autoComplete context. #300

Closed NikDeKur closed 5 months ago

NikDeKur commented 5 months ago

Consider a situation where there is a slash command with 2 fields - field 1 and field 2. Field 2 has auto-complete, the value of which depends on the value of field 1.

When a developer wants to implement such logic, he just wants to access a variable with a value, but for this he needs to redefine the variable of the Arguments class ('override val parseForAutocomplete = true'). Perhaps, from the optimization side, this is a good step, but not the most obvious one for developers.

Also, in such a situation, a problem arises if the user decides to specify the value of field 2 first, and not field 1, then an error will be caused when receiving the value of field 1. Everything would be fine, the error can be caught and handled accordingly, but the description and class of the error are not at all obvious.

The error is as follows: kotlin.UninitializedPropertyAccessException: lateinit property parsed has not been initialized

I suggest replacing this error with a more understandable one so that it is easier for developers to understand the cause of the error, and I also suggest adding a mention of the parseForAutocomplete field in the error description (at the moment, the UninitializedPropertyAccessException error also occurs if parseForAutocomplete = false.)

gdude2002 commented 5 months ago

Pushed to 1.8.0-SNAPSHOT, which should be available in about 15 minutes.

Thanks for the issue!

The full text is as follows:

Parsed value accessed before it has been filled.

This may happen when arguments are accessed from other argument builders out of order, users provide arguments in the wrong order, or previous arguments are accessed in autoComplete builders and parseForAutocomplete is not overridden to be true in your Arguments subclass.

If you believe this exception was thrown due to a bug, please raise an issue on the Kord Extensions GitHub, or ask about it on the Kord Extensions Discord server.