Scripts that load Lua content from external sources need to validate it before parsing. Currently the only signal is a thrown exception from ConvertFrom-Lua. PowerShell's Test-Json sets the established pattern for serialization-format validators: returns [bool], writes parser errors to the error stream when invalid.
Request
Desired capability
Test-Lua -Path settings.lua # validate a file
$content | Test-Lua # validate a string
'{ invalid' | Test-Lua # returns $false, writes error
Parameters
| Parameter |
Description |
-Path |
File path to validate (parameter set: Path) |
-LiteralPath |
Literal path (parameter set: LiteralPath) |
-InputObject |
String to validate (ValueFromPipeline, default set) |
Acceptance criteria
- Returns
$true when content is valid Lua table syntax
- Returns
$false when content is invalid; the parser error is written to the error stream
- Accepts pipeline input as a string
- Mirrors
Test-Json parameter shape and behavior
Technical decisions
Implementation: Wraps ConvertFrom-Lua in try/catch. On exception, writes the parser error via Write-Error and returns $false. On success, returns $true.
Function placement: src/functions/public/Test-Lua.ps1.
No new parser logic: Reuses the existing ConvertFrom-Lua parser. This keeps validation behavior consistent with parsing behavior.
Output type: [bool] only — never throws on invalid input (terminating errors only on argument errors).
Implementation plan
Scripts that load Lua content from external sources need to validate it before parsing. Currently the only signal is a thrown exception from
ConvertFrom-Lua. PowerShell'sTest-Jsonsets the established pattern for serialization-format validators: returns[bool], writes parser errors to the error stream when invalid.Request
Desired capability
Parameters
-PathPath)-LiteralPathLiteralPath)-InputObjectValueFromPipeline, default set)Acceptance criteria
$truewhen content is valid Lua table syntax$falsewhen content is invalid; the parser error is written to the error streamTest-Jsonparameter shape and behaviorTechnical decisions
Implementation: Wraps
ConvertFrom-Luaintry/catch. On exception, writes the parser error viaWrite-Errorand returns$false. On success, returns$true.Function placement:
src/functions/public/Test-Lua.ps1.No new parser logic: Reuses the existing
ConvertFrom-Luaparser. This keeps validation behavior consistent with parsing behavior.Output type:
[bool]only — never throws on invalid input (terminating errors only on argument errors).Implementation plan
Test-Luainsrc/functions/public/Test-Lua.ps1