ArgumentChecker
Package: Libraries.Fabrication · Inherits from: Libraries.Language.Object
The ArgumentChecker class validates the values handed to the fabrication libraries' Set actions, so a bad setting stops the program right where it was given instead of as a hang or a strange print much later (a line width of 0, for example, makes every fill loop run forever). A failed check stops with an InvalidArgumentError (or a FileNotFoundError) whose message says which action, which value and what was wrong, so callers can also catch it with check / detect.
Example Code
use Libraries.Fabrication.ArgumentChecker
use Libraries.Language.Errors.InvalidArgumentError
class Main
action Main
ArgumentChecker checker
check
checker:RequirePositive("Example:SetWidth width", 0)
detect e is InvalidArgumentError
output e:GetErrorMessage()
// Example:SetWidth width must be greater than 0, but was 0.0
end
end
end
Actions
Fail(text message)
Stops with an InvalidArgumentError carrying this message.
Parameters
messagetext: What was wrong.
Example
use Libraries.Fabrication.ArgumentChecker
text adhesion = "raft"
if adhesion not= "none" and adhesion not= "skirt" and adhesion not= "brim"
ArgumentChecker checker
checker:Fail("adhesion must be none, skirt or brim, but was " + adhesion)
end
RequireAtLeast(text name, number value, number minimum)
Stops unless the value is at least the minimum.
Parameters
nametext: What is being checked.valuenumber: The value to check.minimumnumber: The smallest allowed value.
Example
use Libraries.Fabrication.ArgumentChecker
integer walls = 3
ArgumentChecker checker
checker:RequireAtLeast("wall count", walls, 0)
RequireFile(text name, Libraries.System.File file)
Stops with a FileNotFoundError unless the file exists. The message gives the absolute path.
Parameters
nametext: What the file is for, such as "G-code".fileLibraries.System.File: The file to check.
Example
use Libraries.System.File
use Libraries.Fabrication.ArgumentChecker
File file
file:SetPath("Outputs/part.gcode")
ArgumentChecker checker
checker:RequireFile("G-code", file)
RequireFile(text name, text path)
Stops with a FileNotFoundError unless the path names an existing file. The message gives the absolute path, since relative paths start in the folder the program runs in, which is easy to get wrong.
Parameters
nametext: What the file is for, such as "start G-code".pathtext: The path to check.
Example
use Libraries.Fabrication.ArgumentChecker
ArgumentChecker checker
checker:RequireFile("start G-code", "Templates/ender3-v2/start.gcode")
RequirePositive(text name, number value)
Stops unless the value is greater than 0.
Parameters
nametext: What is being checked, such as "PathGenerator:SetLineWidth width".valuenumber: The value to check.
Example
use Libraries.Fabrication.ArgumentChecker
number width = 0.4
ArgumentChecker checker
checker:RequirePositive("line width", width)
RequireRange(text name, number value, number minimum, number maximum)
Stops unless minimum <= value <= maximum.
Parameters
nametext: What is being checked.valuenumber: The value to check.minimumnumber: The smallest allowed value.maximumnumber: The largest allowed value.
Example
use Libraries.Fabrication.ArgumentChecker
number density = 0.2
ArgumentChecker checker
checker:RequireRange("infill density", density, 0, 1)