PopUpMenu.item throws errors if item list is empty
Attempting to access an item from PopUpMenu will fail with an error if the item list is either non-instantiated or empty. The error message is the same as attempting to access an element of an non-instantiated or empty collection, which makes debugging difficult and time-consuming. This can come up when the menu item list is automatically populated and there is a chance it could be empty (in my case, selecting a hardware peripheral).
Environment
- SuperCollider version: 3.11.2
- Operating system: Linux (Pop!_OS 22.04)
Steps to reproduce
m = PopUpMenu();
m.item.postln; // fails with "Message 'at' not understood"
m.items = [];
m.item.postln; // fails with "Primitive '_BasicAt' failed."
Expected vs. actual behavior
Expected: return nil with no error or fail with a more informative error Actual: misleading error
Could be fixed by overwriting the item getter in the PopUpMenu class, so something along
item {
^if(this.value.isNil, {
nil
}, {
items.at( this.value )
});
}
Do you want to make a PR, @daveriedstra ?
I'd be glad to! It might be a while before I have the time though, so if someone else gets to it first that's fine too :)