parseLogFileWithEngine parses a log file using a specific engine or falls back to auto-detection
(filePath string, detectedEngine workflow.CodingAgentEngine, isGitHubCopilotCodingAgent bool, verbose bool)
| 22 | |
| 23 | // parseLogFileWithEngine parses a log file using a specific engine or falls back to auto-detection |
| 24 | func parseLogFileWithEngine(filePath string, detectedEngine workflow.CodingAgentEngine, isGitHubCopilotCodingAgent bool, verbose bool) (LogMetrics, error) { |
| 25 | logsParsingEnginesLog.Printf("Parsing log file: %s, isGitHubCopilotCodingAgent=%v", filePath, isGitHubCopilotCodingAgent) |
| 26 | // Read the entire log file at once to avoid JSON parsing issues from chunked reading |
| 27 | content, err := os.ReadFile(filePath) |
| 28 | if err != nil { |
| 29 | logsParsingEnginesLog.Printf("Failed to read log file: %v", err) |
| 30 | return LogMetrics{}, fmt.Errorf("error reading log file: %w", err) |
| 31 | } |
| 32 | |
| 33 | logContent := string(content) |
| 34 | logsParsingEnginesLog.Printf("Read %d bytes from log file", len(logContent)) |
| 35 | |
| 36 | // If this is a GitHub Copilot coding agent run, use the specialized parser |
| 37 | if isGitHubCopilotCodingAgent { |
| 38 | logsParsingEnginesLog.Print("Using GitHub Copilot coding agent parser") |
| 39 | return ParseCopilotCodingAgentLogMetrics(logContent, verbose), nil |
| 40 | } |
| 41 | |
| 42 | // If we have a detected engine from aw_info.json, use it directly |
| 43 | if detectedEngine != nil { |
| 44 | logsParsingEnginesLog.Printf("Using detected engine: %s", detectedEngine.GetID()) |
| 45 | return detectedEngine.ParseLogMetrics(logContent, verbose), nil |
| 46 | } |
| 47 | |
| 48 | // No aw_info.json metadata available - use fallback parser with common error patterns |
| 49 | logsParsingEnginesLog.Print("No engine detected, using fallback parser with common error patterns") |
| 50 | if verbose { |
| 51 | fmt.Fprintln(os.Stderr, console.FormatWarningMessage("No aw_info.json found, using fallback parser")) |
| 52 | } |
| 53 | |
| 54 | // Use empty metrics for fallback case |
| 55 | var metrics LogMetrics |
| 56 | |
| 57 | return metrics, nil |
| 58 | } |