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

Function parseWasmError

pkg/policies/engine/wasm/errors.go:105–156  ·  view source on GitHub ↗

parseWasmError parses a WASM execution error into a user-friendly PolicyError

(err error)

Source from the content-addressed store, hash-verified

103
104// parseWasmError parses a WASM execution error into a user-friendly PolicyError
105func parseWasmError(err error) *PolicyError {
106 if err == nil {
107 return nil
108 }
109
110 errStr := err.Error()
111
112 // Try pattern matching for known error types
113 for _, ep := range errorPatterns {
114 if matches := ep.pattern.FindStringSubmatch(errStr); matches != nil {
115 message, hint := ep.extract(matches)
116 return &PolicyError{
117 Category: ep.category,
118 UserMessage: message,
119 Hint: hint,
120 OriginalErr: err,
121 }
122 }
123 }
124
125 // Fallback: extract first meaningful line before stack trace
126 lines := strings.Split(errStr, "\n")
127 for _, line := range lines {
128 line = strings.TrimSpace(line)
129
130 // Stop at stack trace markers
131 if line == "" || strings.HasPrefix(line, "wasm stack trace:") || strings.HasPrefix(line, "\t") {
132 break
133 }
134
135 // Clean up wazero artifacts
136 line = strings.ReplaceAll(line, " (recovered by wazero)", "")
137 line = strings.TrimSpace(line)
138
139 if line != "" {
140 return &PolicyError{
141 Category: CategoryUnknown,
142 UserMessage: line,
143 Hint: "Enable debug logging with --debug for more details.",
144 OriginalErr: err,
145 }
146 }
147 }
148
149 // Ultimate fallback
150 return &PolicyError{
151 Category: CategoryUnknown,
152 UserMessage: "Policy execution failed",
153 Hint: "Enable debug logging with --debug for detailed error information.",
154 OriginalErr: err,
155 }
156}
157
158// extractHostname extracts the hostname from a URL string
159func extractHostname(urlStr string) string {

Callers 3

VerifyMethod · 0.85
TestParseWasmErrorFunction · 0.85
TestRealWorldErrorsFunction · 0.85

Calls 1

ErrorMethod · 0.65

Tested by 2

TestParseWasmErrorFunction · 0.68
TestRealWorldErrorsFunction · 0.68