跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

message_test.go

43 行 · 1.5 KB历史下载
1package usererror
2
3import (
4 "context"
5 "crypto/x509"
6 "errors"
7 "io/fs"
8 "net"
9 "net/url"
10 "strings"
11 "syscall"
12 "testing"
13)
14
15func TestKnownFailureIsReadableAndPreservesCause(t *testing.T) {
16 for _, tc := range []struct {
17 cause error
18 reason string
19 }{
20 {context.DeadlineExceeded, "超时"},
21 {&url.Error{Op: "GET", URL: "https://user:[email protected]/secret", Err: &net.DNSError{Err: "no such host", Name: "secret.example"}}, "域名"},
22 {&fs.PathError{Op: "open", Path: "/private-secret/file", Err: fs.ErrPermission}, "拒绝访问"},
23 {syscall.ENOSPC, "空间不足"},
24 {syscall.ECONNREFUSED, "拒绝了连接"},
25 {x509.UnknownAuthorityError{}, "证书"},
26 } {
27 err := Wrap("连接更新源", tc.cause, "请检查所选代理。")
28 if !strings.Contains(err.Error(), tc.reason) || !strings.Contains(err.Error(), "连接更新源") || strings.Contains(err.Error(), "private") {
29 t.Fatalf("unsafe or vague error: %v", err)
30 }
31 if !errors.Is(err, tc.cause) {
32 t.Fatal("original error identity lost")
33 }
34 }
35 precise := errors.New("上传窗口已关闭,请重新选择文件")
36 if Display("上传", precise, "") != precise {
37 t.Fatal("specific application message was replaced")
38 }
39 localized := &fs.PathError{Op: "open", Path: "/Users/测试用户/private-secret", Err: fs.ErrPermission}
40 if message := Display("保存配置", localized, "请检查写入权限。").Error(); !strings.Contains(message, "拒绝访问") || strings.Contains(message, "private-secret") {
41 t.Fatalf("localized system error bypassed safe explanation: %s", message)
42 }
43}