Skip to content

Report each builtin's own name when it errors - #1008

Merged
joaopapereira merged 2 commits into
carvel-dev:developfrom
MaxFreedomPollard:fix-builtin-names-in-errors
Oct 3, 2026
Merged

joaopapereira merged 2 commits into
carvel-dev:developfrom
MaxFreedomPollard:fix-builtin-names-in-errors

Conversation

@MaxFreedomPollard

Copy link
Copy Markdown
Contributor

Summary

Two builtins in the standard library are registered under a different function's name, so when one of them fails, ytt names a function the user never called.

pkg/yttlibrary/math.go:118 registers the mod member as m.newBinaryBuiltin("round", math.Mod). core.ErrWrapper prefixes every error with f.Name() (pkg/template/core/errs.go:30), so math.mod(5) fails with round: expected exactly two arguments. math.round is a real function in the same module, so the message points at the wrong call.

pkg/yttlibrary/overlay/api.go:323 returns the matcher built by overlay.not_op as starlark.NewBuiltin("overlay.or_op", ...), copied from OrOp directly above it. An error raised while matching under @overlay/match by=overlay.not_op(...) comes back as overlay.or_op.

Each builtin now carries its own name. Nothing else changes: mod still calls math.Mod and not_op still negates its matcher.

I checked every other starlark.NewBuiltin call under pkg/ for the same slip. These two are the only ones that name a different function.

Testing

One filetest per module, both asserting the error text:

  • pkg/yamltemplate/filetests/ytt-library/math-mod-err.tpltest
  • pkg/yamltemplate/filetests/ytt-library/overlay/not-op-err.tpltest

With the two source changes reverted and the new tests kept, go test -count=1 ./pkg/yamltemplate/... fails on both, showing the old names:

--- FAIL: TestYAMLTemplate/filetests/ytt-library/math-mod-err.tpltest
        result:   - round: expected exactly two arguments
        expected: - mod: expected exactly two arguments
--- FAIL: TestYAMLTemplate/filetests/ytt-library/overlay/not-op-err.tpltest
        result:   - overlay.apply: Array item on line stdin:13: overlay.or_op: expected starlark.Bool, but was starlark.String
        expected: - overlay.apply: Array item on line stdin:13: overlay.not_op: expected starlark.Bool, but was starlark.String

Local runs on macOS arm64 with Go 1.26.4, on 7 Sep 2026:

  • go test -count=1 ./... passes, test/e2e and test/filetests included, against a ytt binary built from this branch
  • gofmt -l pkg/yttlibrary/math.go pkg/yttlibrary/overlay/api.go prints nothing
  • git diff --check is clean

Branched from develop at 6a94bf4.

Two builtins in the ytt standard library were registered under a
different function's name, so a failing call named a function the user
had not called.

pkg/yttlibrary/math.go:118 registered the "mod" member as
m.newBinaryBuiltin("round", math.Mod). core.ErrWrapper
(pkg/template/core/errs.go:30) prefixes every error with f.Name(), so
math.mod(5) failed with "round: expected exactly two arguments".
math.round is a real function in the same module, so the message
pointed at the wrong call.

pkg/yttlibrary/overlay/api.go:323 returned the matcher built by
overlay.not_op as starlark.NewBuiltin("overlay.or_op", ...), copied
from OrOp directly above it. An error raised while matching under
@overlay/match by=overlay.not_op(...) was reported as overlay.or_op.

Each builtin now carries its own name. Behaviour is otherwise
unchanged. Two filetests cover the error text, one per module.

Signed-off-by: Max Freedom Pollard <[email protected]>
@carvel-bot carvel-bot added this to Carvel Sep 7, 2026

@joaopapereira joaopapereira left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm

@joaopapereira
joaopapereira merged commit f41013d into carvel-dev:develop Oct 3, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants