NewStructuredViolation creates a PolicyViolation from a structured (map) violation object. The object must contain a "message" string field. The full object is preserved in RawFinding for downstream validation.
(policyName string, obj map[string]any)
| 195 | // violation object. The object must contain a "message" string field. |
| 196 | // The full object is preserved in RawFinding for downstream validation. |
| 197 | func NewStructuredViolation(policyName string, obj map[string]any) (*PolicyViolation, error) { |
| 198 | msg, ok := obj["message"] |
| 199 | if !ok { |
| 200 | return nil, fmt.Errorf("missing required \"message\" field in structured violation") |
| 201 | } |
| 202 | |
| 203 | msgStr, ok := msg.(string) |
| 204 | if !ok { |
| 205 | return nil, fmt.Errorf("\"message\" field must be a string, got %T", msg) |
| 206 | } |
| 207 | |
| 208 | return &PolicyViolation{ |
| 209 | Subject: policyName, |
| 210 | Violation: msgStr, |
| 211 | RawFinding: obj, |
| 212 | }, nil |
| 213 | } |
| 214 | |
| 215 | type ResultFormatError struct { |
| 216 | Field string |
no outgoing calls
no test coverage detected