@@ -146,6 +146,7 @@ func (f *WasmtimeFn) Run(r io.Reader, w io.Writer) error {
146
146
if err != nil {
147
147
return fmt .Errorf ("unable to invoke %v: %v" , jsEntrypointFunction , err )
148
148
}
149
+
149
150
// We expect `result` to be a *wasmexec.jsString (which is not exportable) with
150
151
// the following definition: type jsString struct { data string }. It will look
151
152
// like `&{realPayload}`
@@ -154,17 +155,33 @@ func (f *WasmtimeFn) Run(r io.Reader, w io.Writer) error {
154
155
// Try to parse the output as yaml.
155
156
resourceListOutput , err := yaml .Parse (resultStr )
156
157
if err != nil {
157
- return fmt .Errorf ("error parsing output resource list %q: %w" , resultStr , err )
158
+ additionalErrorMessage , errorResultRetrievalErr := retrieveError (f , resourceList )
159
+ if errorResultRetrievalErr != nil {
160
+ return errorResultRetrievalErr
161
+ }
162
+ return fmt .Errorf ("parsing output resource list with content: %q\n %w\n %s" , resultStr , err , additionalErrorMessage )
158
163
}
159
164
if resourceListOutput .GetKind () != "ResourceList" {
160
- return fmt .Errorf ("invalid resource list output from wasm library; got %q" , resultStr )
165
+ additionalErrorMessage , errorResultRetrievalErr := retrieveError (f , resourceList )
166
+ if errorResultRetrievalErr != nil {
167
+ return errorResultRetrievalErr
168
+ }
169
+ return fmt .Errorf ("invalid resource list output from wasm library; got %q\n %s" , resultStr , additionalErrorMessage )
161
170
}
162
171
if _ , err = w .Write ([]byte (resultStr )); err != nil {
163
172
return fmt .Errorf ("unable to write the output resource list: %w" , err )
164
173
}
165
174
return f .loader .cleanup ()
166
175
}
167
176
177
+ func retrieveError (f * WasmtimeFn , resourceList []byte ) (string , error ) {
178
+ errResult , err := f .gomod .Call (jsEntrypointFunction + "Errors" , string (resourceList ))
179
+ if err != nil {
180
+ return "" , fmt .Errorf ("unable to retrieve additional error message from function: %w" , err )
181
+ }
182
+ return fmt .Sprintf ("%s" , errResult ), nil
183
+ }
184
+
168
185
var _ wasmexec.Instance = & WasmtimeFn {}
169
186
170
187
func (f * WasmtimeFn ) GetSP () (uint32 , error ) {
0 commit comments