-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patherrors_test.go
More file actions
119 lines (101 loc) · 3.34 KB
/
errors_test.go
File metadata and controls
119 lines (101 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package codexsdk
import (
"fmt"
"testing"
"github.com/stretchr/testify/require"
)
// TestCLINotFoundError_Creation tests CLINotFoundError creation and formatting.
func TestCLINotFoundError_Creation(t *testing.T) {
searchedPaths := []string{
"$PATH",
"/usr/local/bin/claude",
"/usr/bin/claude",
}
err := &CLINotFoundError{
SearchedPaths: searchedPaths,
}
require.Error(t, err)
require.Contains(t, err.Error(), "codex CLI not found")
require.Contains(t, err.Error(), "$PATH")
require.Contains(t, err.Error(), "/usr/local/bin/claude")
}
// TestCLIConnectionError_Creation tests CLIConnectionError creation and formatting.
func TestCLIConnectionError_Creation(t *testing.T) {
innerErr := fmt.Errorf("connection refused")
err := &CLIConnectionError{
Err: innerErr,
}
require.Error(t, err)
require.Contains(t, err.Error(), "failed to connect to CLI")
require.Contains(t, err.Error(), "connection refused")
}
// TestProcessError_WithExitCodeAndStderr tests ProcessError with exit code and stderr.
func TestProcessError_WithExitCodeAndStderr(t *testing.T) {
err := &ProcessError{
ExitCode: 1,
Stderr: "Error: authentication failed",
Err: nil,
}
require.Error(t, err)
require.Contains(t, err.Error(), "CLI process failed")
require.Contains(t, err.Error(), "exit 1")
require.Contains(t, err.Error(), "authentication failed")
}
// TestMessageParseError_Creation tests MessageParseError creation and formatting.
func TestMessageParseError_Creation(t *testing.T) {
innerErr := fmt.Errorf("invalid JSON")
err := &MessageParseError{
Message: `{"incomplete": `,
Err: innerErr,
Data: map[string]any{
"incomplete": true,
},
}
require.Error(t, err)
require.Contains(t, err.Error(), "failed to parse message")
require.Contains(t, err.Error(), "invalid JSON")
}
// TestMessageParseError_PreservesMessage tests that MessageParseError preserves the original message.
func TestMessageParseError_PreservesMessage(t *testing.T) {
err := &MessageParseError{
Message: `{"type": "unknown", "data": 123}`,
Err: fmt.Errorf("unknown type"),
Data: map[string]any{
"type": "unknown",
"data": 123,
},
}
require.Equal(t, `{"type": "unknown", "data": 123}`, err.Message)
require.Equal(t, "unknown", err.Data["type"])
require.Equal(t, 123, err.Data["data"])
}
// TestCLIJSONDecodeError_Creation tests CLIJSONDecodeError creation and formatting.
func TestCLIJSONDecodeError_Creation(t *testing.T) {
innerErr := fmt.Errorf("unexpected end of JSON input")
err := &CLIJSONDecodeError{
RawData: `{"incomplete": `,
Err: innerErr,
}
require.Error(t, err)
require.Contains(t, err.Error(), "failed to decode JSON from CLI")
require.Contains(t, err.Error(), "unexpected end of JSON input")
}
// TestCLIJSONDecodeError_PreservesRawData tests that raw data is preserved.
func TestCLIJSONDecodeError_PreservesRawData(t *testing.T) {
rawData := `{"type": "user", invalid}`
err := &CLIJSONDecodeError{
RawData: rawData,
Err: fmt.Errorf("invalid character"),
}
require.Equal(t, rawData, err.RawData)
require.Contains(t, err.Error(), "invalid character")
}
// TestCLIJSONDecodeError_Unwrap tests that the underlying error can be unwrapped.
func TestCLIJSONDecodeError_Unwrap(t *testing.T) {
innerErr := fmt.Errorf("syntax error")
err := &CLIJSONDecodeError{
RawData: `{bad}`,
Err: innerErr,
}
require.ErrorIs(t, err, innerErr)
}