MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / TestRealWorldErrors

Function TestRealWorldErrors

pkg/policies/engine/wasm/errors_test.go:283–327  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

281}
282
283func TestRealWorldErrors(t *testing.T) {
284 // Test actual error messages seen from Extism/wazero
285 realWorldErrors := []struct {
286 name string
287 err string
288 expectedCategory ErrorCategory
289 }{
290 {
291 name: "Extism HTTP forbidden",
292 err: `HTTP request to 'https://registry.npmjs.org/lodash' is not allowed (recovered by wazero)
293wasm stack trace:
294 extism:host/env.http_request(i64,i64) i64
295 main.Execute() i32
296 0x2a26b: /Users/user/go/pkg/mod/github.com/extism/go-pdk@v1.1.3/extism_pdk.go:394:34 (inlined)
297 /Users/user/go/pkg/mod/github.com/extism/go-pdk@v1.1.3/internal/memory/memory.go:234:37 (inlined)
298 /Users/user/go/pkg/mod/github.com/extism/go-pdk@v1.1.3/env.go:271:12`,
299 expectedCategory: CategoryHTTPForbidden,
300 },
301 {
302 name: "Context timeout",
303 err: `context deadline exceeded (recovered by wazero)
304wasm stack trace:
305 main.Execute() i32`,
306 expectedCategory: CategoryTimeout,
307 },
308 {
309 name: "Memory limit",
310 err: `out of memory (recovered by wazero)
311wasm stack trace:
312 malloc(i32) i32
313 main.Execute() i32`,
314 expectedCategory: CategoryMemory,
315 },
316 }
317
318 for _, tt := range realWorldErrors {
319 t.Run(tt.name, func(t *testing.T) {
320 parsed := parseWasmError(errors.New(tt.err))
321 require.NotNil(t, parsed)
322 assert.Equal(t, tt.expectedCategory, parsed.Category)
323 assert.NotEmpty(t, parsed.UserMessage)
324 assert.NotEmpty(t, parsed.Hint)
325 })
326 }
327}

Callers

nothing calls this directly

Calls 2

parseWasmErrorFunction · 0.85
RunMethod · 0.45

Tested by

no test coverage detected