Graceful Errors for Plugin Devs

In my plugin, I have made a bunch of configuration options. In many of these, the wrong value can cause a js error. Now I can catch these errors or sanitize the inputs to prevent the js from erroring at all, but the plugin would still not behave correctly in these cases. How do you recommend I display that there was an error and how to fix it back to the user? I think a console log would be pretty useless for most people, and the red js error screen is scary and unhelpful.

I would look at the Alert Mechanism: https://tiddlywiki.com/#AlertMechanism

For invalid widget attributes, I often use the ErrorWidget to display feedback:
https://tiddlywiki.com/#ErrorWidget

2 Likes

In the core every widget or macro parameter is checked if it contains a value. If the parameter is not defined or empty, it is initialized with a sane default value that works.

So every input parameter has to be sanity checked, if it has the right type, that is expected by the code. If you have a sanity check at the beginning, you do not need to have extra code when you use the value and there should be no js-errors anymore.

Most core widgets fail silently. So they produce no output if parameters are completely wrong and cannot be fixed. If there is a fallback behaviour that works it will be used. eg: $error-widget.

The RSOD is a last resort of the core itself, if the user code does not have sanity checks. So the core cannot guarantee that there is no data-loss. It is much better to scare a user than to loose data. Data loss has to be avoided at all cost.

I hope that makes sense.
-m