Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion services/core/internal/api/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,13 @@ func writeOperationError(w http.ResponseWriter, r *http.Request, err error) {
const invalidInputMessage = "Invalid resource identifier or request limits."

// writeInternalError reports an unmapped failure. Driver errors can include
// submitted values, so the raw error is never logged.
// submitted values, so the raw error is never logged. Once the client has gone,
// the failure is its ended request context: nothing is reported, and the request
// log records the request as aborted.
func writeInternalError(w http.ResponseWriter, r *http.Request) {
if r.Context().Err() != nil {
return
}
log.Ctx(r.Context()).Error("oac-core persistence operation failed")
writeError(w, http.StatusInternalServerError, "internal_error", "The operation could not be completed.")
}
Expand Down
4 changes: 1 addition & 3 deletions services/core/internal/api/errors_agents.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"
"net/http"

"github.com/MiniMax-AI/OpenAgentCore/internal/obs/log"
"github.com/MiniMax-AI/OpenAgentCore/services/core/internal/agents"
)

Expand All @@ -19,7 +18,6 @@ func writeAgentsError(w http.ResponseWriter, r *http.Request, err error) {
case errors.Is(err, agents.ErrInvalidInput):
writeError(w, http.StatusBadRequest, "invalid_request", "Invalid resource identifier or request limits.")
default:
log.Ctx(r.Context()).Error("oac-core persistence operation failed")
writeError(w, http.StatusInternalServerError, "internal_error", "The operation could not be completed.")
writeInternalError(w, r)
}
}
5 changes: 1 addition & 4 deletions services/core/internal/api/errors_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"net/http"
"strings"

"github.com/MiniMax-AI/OpenAgentCore/internal/obs/log"
"github.com/MiniMax-AI/OpenAgentCore/services/core/internal/files"
)

Expand All @@ -28,8 +27,6 @@ func writeFilesError(w http.ResponseWriter, r *http.Request, err error, notFound
case errors.Is(err, files.ErrInvalidInput):
writeError(w, http.StatusBadRequest, "invalid_request", "Invalid resource identifier or request limits.")
default:
// Storage failures can include submitted values; do not log the error.
log.Ctx(r.Context()).Error("oac-core persistence operation failed")
writeError(w, http.StatusInternalServerError, "internal_error", "The operation could not be completed.")
writeInternalError(w, r)
}
}
12 changes: 12 additions & 0 deletions services/core/internal/api/errors_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package api

import (
"context"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -197,3 +198,14 @@ func TestSharedPersistenceErrors(t *testing.T) {
}
}
}

// A client that has gone gets no error report: its ended context is the failure.
func TestInternalErrorAfterClientAbort(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
cancel()
response := httptest.NewRecorder()
writeAgentsError(response, httptest.NewRequest(http.MethodGet, "/v1/agents", nil).WithContext(ctx), context.Canceled)
if response.Body.Len() != 0 {
t.Fatal(response.Body)
}
}
Loading