BOSL2 icon indicating copy to clipboard operation
BOSL2 copied to clipboard

[BUG] str_split goes berserk if the input string is undef

Open MethylBromide opened this issue 1 year ago • 2 comments

Describe the bug If the input argument is undef value, str_split goes into an apparent infinite loop of error messages.

I could see ONE warning in this case, but what actually occurs is the OpenSCAD client is permanently locked up executing this script. To be able to do anything again I have to use Windows Task Manager to explicitly shut down the background process that's executing the script, which OpenSCAD fails to terminate when the UI is closed.

Code To Reproduce Bug

include <BOSL2/std.scad>
result = str_split(data, ".");
echo(result);

Expected behavior ECHO: undef and maybe ONE warning message

Additional context Add any other context about the problem here.

  • OpenSCAD Version: 2024.11.14 (git bc0d078e0) for Windows 64-bit
  • Other libraries used: none

MethylBromide avatar Jan 08 '25 01:01 MethylBromide

Wow, while obviously it shouldn't do that, this is also a pretty good argument for why everyone should turn "stop on first warnings" on.

adrianVmariano avatar Jan 08 '25 01:01 adrianVmariano

While str_split should handle invalid input gracefully, returning undef may not be ideal. Validating arguments and providing a meaningful error can prevent infinite loops. Passing undef usually indicates an upstream issue that should be addressed.

JasonKoolman avatar Jan 08 '25 13:01 JasonKoolman