Skip to content

Commit 44f2cb3

Browse files
committed
Fix warnings parsing
1 parent 0a41f3f commit 44f2cb3

2 files changed

Lines changed: 27 additions & 13 deletions

File tree

pkg/executor/executor.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,12 @@ func (e *CLIExecutor) Run(apexCode string, org string) (string, error) {
8686
return "", fmt.Errorf("sf apex run failed: %w\nOutput: %s", err, string(output))
8787
}
8888

89+
// Extract JSON from output (skip warning messages)
90+
jsonOutput := extractJSON(string(output))
91+
8992
// Parse JSON response
9093
var response ApexRunResponse
91-
if err := json.Unmarshal(output, &response); err != nil {
94+
if err := json.Unmarshal([]byte(jsonOutput), &response); err != nil {
9295
return "", fmt.Errorf("failed to parse sf apex run JSON output: %w\nOutput: %s", err, string(output))
9396
}
9497

@@ -159,6 +162,17 @@ func (e *CLIExecutor) ExecuteParallel(apexCode string, runs int, maxConcurrent i
159162
return results, nil
160163
}
161164

165+
// extractJSON finds the first JSON object in the output string
166+
// This handles cases where sf CLI outputs warnings before the JSON
167+
func extractJSON(output string) string {
168+
// Find the first '{' character
169+
start := strings.Index(output, "{")
170+
if start == -1 {
171+
return output
172+
}
173+
return output[start:]
174+
}
175+
162176
// createTempApexFile writes Apex code to a temporary file
163177
func createTempApexFile(apexCode string) (string, error) {
164178
tmpFile, err := os.CreateTemp("", "apex-bench-*.apex")

pkg/generator/templates.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ for (Integer i = 0; i < warmupIterations; i++) {
2121
// Measurement phase
2222
Long totalWallTime = 0;
2323
Long totalCpuTime = 0;
24-
Long minWallTime = Long.MAX_VALUE;
25-
Long maxWallTime = 0;
26-
Integer minCpuTime = Integer.MAX_VALUE;
27-
Integer maxCpuTime = 0;
24+
Long minWallTime = null;
25+
Long maxWallTime = null;
26+
Integer minCpuTime = null;
27+
Integer maxCpuTime = null;
2828
2929
{{if .TrackHeap}}
3030
Long totalHeapUsed = 0;
31-
Long minHeapUsed = Long.MAX_VALUE;
32-
Long maxHeapUsed = 0;
31+
Long minHeapUsed = null;
32+
Long maxHeapUsed = null;
3333
{{end}}
3434
3535
{{if .TrackDB}}
@@ -54,8 +54,8 @@ for (Integer i = 0; i < measurementIterations; i++) {
5454
Long heapAfter = Limits.getHeapSize();
5555
Long heapDelta = heapAfter - heapBefore;
5656
totalHeapUsed += heapDelta;
57-
if (heapDelta < minHeapUsed) minHeapUsed = heapDelta;
58-
if (heapDelta > maxHeapUsed) maxHeapUsed = heapDelta;
57+
if (minHeapUsed == null || heapDelta < minHeapUsed) minHeapUsed = heapDelta;
58+
if (maxHeapUsed == null || heapDelta > maxHeapUsed) maxHeapUsed = heapDelta;
5959
{{end}}
6060
6161
Long wallDelta = wallEnd - wallStart;
@@ -64,10 +64,10 @@ for (Integer i = 0; i < measurementIterations; i++) {
6464
totalWallTime += wallDelta;
6565
totalCpuTime += cpuDelta;
6666
67-
if (wallDelta < minWallTime) minWallTime = wallDelta;
68-
if (wallDelta > maxWallTime) maxWallTime = wallDelta;
69-
if (cpuDelta < minCpuTime) minCpuTime = cpuDelta;
70-
if (cpuDelta > maxCpuTime) maxCpuTime = cpuDelta;
67+
if (minWallTime == null || wallDelta < minWallTime) minWallTime = wallDelta;
68+
if (maxWallTime == null || wallDelta > maxWallTime) maxWallTime = wallDelta;
69+
if (minCpuTime == null || cpuDelta < minCpuTime) minCpuTime = cpuDelta;
70+
if (maxCpuTime == null || cpuDelta > maxCpuTime) maxCpuTime = cpuDelta;
7171
}
7272
7373
{{if .TrackDB}}

0 commit comments

Comments
 (0)