Plan for sane script error reporting
Jump to navigation
Jump to search
People often don't notice when they are passing invalid arguments to script commands. Sometimes it's hard to tell whether an error occurred (see bug 36). Most of the time it's just a misunderstanding of the command arguments or a bug in their script. Only certain errors, such as in read/write global, actually display an error. A few print to g_debug.txt and ignore.
In the majority of cases there is no need to silently accept invalid arguments. Error reporting is sought.
- Improve scripterr:
HSpeak should compile a list of function names pulled from plotscr.hsd into a HS sub-lumpprovide a hardcoded list of existing command names for backwards compatibility with old scripts (perhaps automatically generated by hspeak when compiling Game)get rid of the command name string arguments to functions like valid_plotslice (I'd like to mention that passing string literals to functions which don't use them is very expensive in FB, this isn't C!)replace/extend scripterr to print information such as current script, current command, and in future line number. We could add other options like "Ignore", "Kill script", "Turn off all script error reporting", "Enter debugger".Obviously, the specific error message (argument out of bounds) should provide a lot more information- (Some ideas for 'debug builds' of scripts can be found at Talk:Henceforth VM#Moving Forward)
- Throw more errors:
add a preference bitset that enables in-game error messages when script errors occur. It would default to off for existing games, on for new, and would be automatically turned on when a game is loaded into Custom accompanied by a message to alert people to the change and how to undo it- carefully replace calls to bound within script command code with a wrapper function that bounds if the error-throwing bitset is off, or throws an error otherwise
- carefully replace non-wrapping checking of command arguments with calls to a function that throws an error if the argument is out of bounds (like valid_plotslice and so on)
replace all debug calls everywhere within the implementation of script commands with a wrapper function that shows a visible error if enabledEven is a visible error message is not shown, we can still report everything in g_debug.txt
- More fire power:
- At Plan for dynamic types in HamsterSpeak 'weak types' are suggested. These could be used to distinguish valid return values from failure indicators like 0 from getNPCID (see below). If you attempted to pass such a failure value to another command expecting some kind of meaningful data (eg NPC reference), an error could be thrown.
Other problems[edit]
- Currently, all menu commands call find_menu_handle or find_menu_item_handle, before checking the return result for validity. This always return -1 on error, so you always get "invalid menu handle -1". Of course, a handle is just a number. Probably need the new interpreter for a real improvement.
Some special warning throwing conditions[edit]
- get NPC ID could throw a warning when passed an NPC ID instead of an NPC reference. 0 is returned from commands such as NPCatspot to indicate failure, which is then frequently fed to getNPCID without checking.