Skip to content

Commit

Permalink
improve wasm error message (#3781)
Browse files Browse the repository at this point in the history
  • Loading branch information
natasha41575 committed Feb 6, 2023
1 parent 5a7e65f commit 9dbfc60
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions internal/fnruntime/wasmtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,12 @@ func (f *WasmtimeFn) Run(r io.Reader, w io.Writer) error {
resultStr := fmt.Sprintf("%s", result)
resultStr = resultStr[2 : len(resultStr)-1]
// Try to parse the output as yaml.
if _, err = yaml.Parse(resultStr); err != nil {
return errors.New(resultStr)
resourceListOutput, err := yaml.Parse(resultStr)
if err != nil {
return fmt.Errorf("error parsing output resource list %q: %w", resultStr, err)
}
if resourceListOutput.GetKind() != "ResourceList" {
return fmt.Errorf("invalid resource list output from wasm library; got %q", resultStr)
}
if _, err = w.Write([]byte(resultStr)); err != nil {
return fmt.Errorf("unable to write the output resource list: %w", err)
Expand Down

0 comments on commit 9dbfc60

Please sign in to comment.