Skip to content

Commit

Permalink
Turn KRM function panics into errors in the built-in runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
kispaljr committed Sep 5, 2024
1 parent 449b42f commit 18ab2a0
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/engine/builtinruntime.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package engine

import (
"context"
"fmt"
"io"

fnsdk "github.com/GoogleContainerTools/kpt-functions-sdk/go/fn"
Expand Down Expand Up @@ -95,6 +96,12 @@ type builtinRunner struct {

var _ fn.FunctionRunner = &builtinRunner{}

func (br *builtinRunner) Run(r io.Reader, w io.Writer) error {
func (br *builtinRunner) Run(r io.Reader, w io.Writer) (err error) {
// KRM functions often panic on input validation errors, so we need to convert panics to errors
defer func() {
if p := recover(); p != nil {
err = fmt.Errorf("KRM function panicked with: %v", p)
}
}()
return fnsdk.Execute(br.processor, r, w)
}

0 comments on commit 18ab2a0

Please sign in to comment.