Handle native structured-format incompatibility and preserve failure evidence
This commit is contained in:
@@ -63,16 +63,27 @@ func (c OpenCodeClient) call(ctx context.Context, method, path string, body any)
|
||||
if c.connection != nil && c.connection.Backend == "v1" {
|
||||
started := time.Now()
|
||||
data, err := c.connection.Call(ctx, method, path, body)
|
||||
if probe := c.connection.FormatProbe; probe != nil {
|
||||
c.Operations.recordFormatProbe(*probe)
|
||||
if !probe.Supported && probe.Diagnostic != "" {
|
||||
c.Operations.record(OperationEvidence{Operation: "get /session/" + probe.SessionID + "/message (format compatibility probe)", Backend: c.Backend, Executable: opencode.Executable(), Directory: c.Directory, ExitCode: -1, HTTPStatus: 400, Diagnostic: probe.Diagnostic, Stdout: probe.Response}, started)
|
||||
}
|
||||
c.connection.FormatProbe = nil
|
||||
}
|
||||
if err != nil {
|
||||
status := 0
|
||||
if match := httpStatusPattern.FindStringSubmatch(err.Error()); len(match) > 0 {
|
||||
status, _ = strconv.Atoi(match[1])
|
||||
}
|
||||
c.Operations.record(OperationEvidence{Operation: method + " " + path, Backend: c.Backend, Executable: opencode.Executable(), Directory: c.Directory, ExitCode: -1, HTTPStatus: status, Diagnostic: err.Error(), Stdout: string(data)}, started)
|
||||
evidenceStatus := status
|
||||
if evidenceStatus == 0 {
|
||||
evidenceStatus = c.connection.LastHTTPStatus
|
||||
}
|
||||
c.Operations.record(OperationEvidence{Operation: method + " " + path, Backend: c.Backend, Executable: opencode.Executable(), Directory: c.Directory, ExitCode: -1, HTTPStatus: evidenceStatus, NativeOperation: c.connection.LastHTTPOperation, Diagnostic: err.Error(), Stdout: string(data)}, started)
|
||||
if ctx.Err() != nil {
|
||||
return nil, ctx.Err()
|
||||
}
|
||||
return nil, &openCodeError{operation: method + " " + path, status: status, cause: err}
|
||||
return nil, &openCodeError{operation: method + " " + path, status: status, cause: err, diagnostic: err.Error()}
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user