fix(cli): align stream error handling after output-mode merge
Follow up on #1740/#1741 by typing terminal SSE errors in the SDK, classifying them as server.error in the CLI/MCP, marking Projector done on error frames, attaching session_id to MCP stream failures, and migrating the e2e chat step to the bounded JSON envelope.
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/Tencent/WeKnora/cli/internal/output"
|
||||
sdk "github.com/Tencent/WeKnora/client"
|
||||
)
|
||||
|
||||
// ErrorCode is a namespaced stable identifier emitted on stderr in the
|
||||
@@ -268,6 +269,21 @@ func WrapHTTP(cause error, format string, args ...any) *Error {
|
||||
return Wrapf(ClassifyHTTPError(cause), cause, format, args...)
|
||||
}
|
||||
|
||||
// ClassifySDKError maps SDK transport, HTTP, and terminal SSE stream errors to
|
||||
// the canonical ErrorCode. SSE terminal frames classify as server.error rather
|
||||
// than network.error.
|
||||
func ClassifySDKError(err error) ErrorCode {
|
||||
if sdk.IsSSEStreamError(err) {
|
||||
return CodeServerError
|
||||
}
|
||||
return ClassifyHTTPError(err)
|
||||
}
|
||||
|
||||
// WrapStream wraps an SDK streaming error with ClassifySDKError.
|
||||
func WrapStream(cause error, format string, args ...any) *Error {
|
||||
return Wrapf(ClassifySDKError(cause), cause, format, args...)
|
||||
}
|
||||
|
||||
// FlagError signals user-visible flag/argument problems; the root command
|
||||
// prints help on top of the message and exits 2.
|
||||
type FlagError struct{ err error }
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
sdk "github.com/Tencent/WeKnora/client"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@@ -35,6 +36,12 @@ func TestClassifyHTTPError(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestClassifySDKError_SSEStreamTerminal(t *testing.T) {
|
||||
err := sdk.NewSSEStreamError("boom")
|
||||
assert.Equal(t, CodeServerError, ClassifySDKError(err))
|
||||
assert.Equal(t, CodeNetworkError, ClassifyHTTPError(err))
|
||||
}
|
||||
|
||||
func TestClassifyHTTPError_500NotFoundRescue(t *testing.T) {
|
||||
// Server's 1003 = ErrNotFound is the only typed "not found" code we
|
||||
// rescue. 1007 = ErrInternalServer is the catch-all bucket — its
|
||||
|
||||
Reference in New Issue
Block a user