FormatParseErrorJSON creates a JSON error output for parse failures
(err error, inputSource string)
| 375 | |
| 376 | // FormatParseErrorJSON creates a JSON error output for parse failures |
| 377 | func FormatParseErrorJSON(err error, inputSource string) ([]byte, error) { |
| 378 | errCode := extractErrorCode(err) |
| 379 | output := &JSONParseOutput{ |
| 380 | Command: "parse", |
| 381 | Input: JSONInputInfo{ |
| 382 | Type: "query", |
| 383 | Files: []string{inputSource}, |
| 384 | Count: 1, |
| 385 | }, |
| 386 | Status: "error", |
| 387 | Error: &JSONParseError{ |
| 388 | Message: err.Error(), |
| 389 | Code: errCode, |
| 390 | Type: categorizeByCode(errCode, err.Error()), |
| 391 | }, |
| 392 | } |
| 393 | |
| 394 | // Marshal to JSON with indentation |
| 395 | data, err2 := json.MarshalIndent(output, "", " ") |
| 396 | if err2 != nil { |
| 397 | return nil, fmt.Errorf("failed to marshal parse error JSON: %w", err2) |
| 398 | } |
| 399 | |
| 400 | return data, nil |
| 401 | } |
| 402 | |
| 403 | // determineInputType determines the type of input based on the file list |
| 404 | func determineInputType(files []string) string { |