Summary
After #111 lands (relaxing WithLogHandler(nil) and WithLogger(nil) to no-op across the three engines' compiler packages), six call sites that exist solely to work around the current nil-rejection become redundant:
| File:line |
Current pattern |
polyscript.go:251-253 |
if cfg.handler != nil { opts = append(opts, risorMachine.WithLogHandler(cfg.handler)) } |
polyscript.go:262-264 |
same shape, starlarkMachine.WithLogHandler |
polyscript.go:273-275 |
same shape, extismMachine.WithLogHandler |
engines/risor/new.go:72-74 |
if cfg.handler != nil { compilerOpts = append(..., compiler.WithLogHandler(cfg.handler)) } |
engines/starlark/new.go:72-74 |
same shape |
engines/extism/new.go:85-87 |
same shape |
Once the underlying option is itself a no-op on nil, the guards do nothing useful — the unconditional append produces identical behavior.
Proposal
Drop all six guards. Each pair of lines collapses to a single unconditional append:
opts = append(opts, risorMachine.WithLogHandler(cfg.handler))
The cfg.handler field is plain slog.Handler whose zero value is nil; the option now handles that correctly. No tests should need updating — the existing "nil handler is fine" tests stay green either way.
Out of scope
- Behavior change for non-nil handlers — unchanged.
- Other defensive nil-checks elsewhere in the codebase — only the six listed above are downstream of this specific design tension.
Files
polyscript.go — three sites
engines/risor/new.go
engines/starlark/new.go
engines/extism/new.go
Depends on
Summary
After #111 lands (relaxing
WithLogHandler(nil)andWithLogger(nil)to no-op across the three engines' compiler packages), six call sites that exist solely to work around the current nil-rejection become redundant:polyscript.go:251-253if cfg.handler != nil { opts = append(opts, risorMachine.WithLogHandler(cfg.handler)) }polyscript.go:262-264starlarkMachine.WithLogHandlerpolyscript.go:273-275extismMachine.WithLogHandlerengines/risor/new.go:72-74if cfg.handler != nil { compilerOpts = append(..., compiler.WithLogHandler(cfg.handler)) }engines/starlark/new.go:72-74engines/extism/new.go:85-87Once the underlying option is itself a no-op on nil, the guards do nothing useful — the unconditional append produces identical behavior.
Proposal
Drop all six guards. Each pair of lines collapses to a single unconditional append:
The
cfg.handlerfield is plainslog.Handlerwhose zero value is nil; the option now handles that correctly. No tests should need updating — the existing "nil handler is fine" tests stay green either way.Out of scope
Files
polyscript.go— three sitesengines/risor/new.goengines/starlark/new.goengines/extism/new.goDepends on
WithLogHandler(nil)to return an error during normal construction with noWithLogHandleroption supplied.