开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
main
分支 (1)
标签 (1)
main
v0.1.0
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
项目仓库所选许可证以仓库主分支所使用许可证为准
main
分支 (1)
标签 (1)
main
v0.1.0
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
main
分支 (1)
标签 (1)
main
v0.1.0
errors.ts 7.48 KB
一键复制 编辑 原始数据 按行查看 历史
sanbucat 提交于 2026年03月31日 17:08 +08:00 . v2.1.88 反编译源码
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 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
import { APIUserAbortError } from '@anthropic-ai/sdk'
export class ClaudeError extends Error {
constructor(message: string) {
super(message)
this.name = this.constructor.name
}
}
export class MalformedCommandError extends Error {}
export class AbortError extends Error {
constructor(message?: string) {
super(message)
this.name = 'AbortError'
}
}
/**
* True iff `e` is any of the abort-shaped errors the codebase encounters:
* our AbortError class, a DOMException from AbortController.abort()
* (.name === 'AbortError'), or the SDK's APIUserAbortError. The SDK class
* is checked via instanceof because minified builds mangle class names —
* constructor.name becomes something like 'nJT' and the SDK never sets
* this.name, so string matching silently fails in production.
*/
export function isAbortError(e: unknown): boolean {
return (
e instanceof AbortError ||
e instanceof APIUserAbortError ||
(e instanceof Error && e.name === 'AbortError')
)
}
/**
* Custom error class for configuration file parsing errors
* Includes the file path and the default configuration that should be used
*/
export class ConfigParseError extends Error {
filePath: string
defaultConfig: unknown
constructor(message: string, filePath: string, defaultConfig: unknown) {
super(message)
this.name = 'ConfigParseError'
this.filePath = filePath
this.defaultConfig = defaultConfig
}
}
export class ShellError extends Error {
constructor(
public readonly stdout: string,
public readonly stderr: string,
public readonly code: number,
public readonly interrupted: boolean,
) {
super('Shell command failed')
this.name = 'ShellError'
}
}
export class TeleportOperationError extends Error {
constructor(
message: string,
public readonly formattedMessage: string,
) {
super(message)
this.name = 'TeleportOperationError'
}
}
/**
* Error with a message that is safe to log to telemetry.
* Use the long name to confirm you've verified the message contains no
* sensitive data (file paths, URLs, code snippets).
*
* Single-arg: same message for user and telemetry
* Two-arg: different messages (e.g., full message has file path, telemetry doesn't)
*
* @example
* // Same message for both
* throw new TelemetrySafeError_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS(
* 'MCP server "slack" connection timed out'
* )
*
* // Different messages
* throw new TelemetrySafeError_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS(
* `MCP tool timed out after ${ms}ms`, // Full message for logs/user
* 'MCP tool timed out' // Telemetry message
* )
*/
export class TelemetrySafeError_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS extends Error {
readonly telemetryMessage: string
constructor(message: string, telemetryMessage?: string) {
super(message)
this.name = 'TelemetrySafeError'
this.telemetryMessage = telemetryMessage ?? message
}
}
export function hasExactErrorMessage(error: unknown, message: string): boolean {
return error instanceof Error && error.message === message
}
/**
* Normalize an unknown value into an Error.
* Use at catch-site boundaries when you need an Error instance.
*/
export function toError(e: unknown): Error {
return e instanceof Error ? e : new Error(String(e))
}
/**
* Extract a string message from an unknown error-like value.
* Use when you only need the message (e.g., for logging or display).
*/
export function errorMessage(e: unknown): string {
return e instanceof Error ? e.message : String(e)
}
/**
* Extract the errno code (e.g., 'ENOENT', 'EACCES') from a caught error.
* Returns undefined if the error has no code or is not an ErrnoException.
* Replaces the `(e as NodeJS.ErrnoException).code` cast pattern.
*/
export function getErrnoCode(e: unknown): string | undefined {
if (e && typeof e === 'object' && 'code' in e && typeof e.code === 'string') {
return e.code
}
return undefined
}
/**
* True if the error is ENOENT (file or directory does not exist).
* Replaces `(e as NodeJS.ErrnoException).code === 'ENOENT'`.
*/
export function isENOENT(e: unknown): boolean {
return getErrnoCode(e) === 'ENOENT'
}
/**
* Extract the errno path (the filesystem path that triggered the error)
* from a caught error. Returns undefined if the error has no path.
* Replaces the `(e as NodeJS.ErrnoException).path` cast pattern.
*/
export function getErrnoPath(e: unknown): string | undefined {
if (e && typeof e === 'object' && 'path' in e && typeof e.path === 'string') {
return e.path
}
return undefined
}
/**
* Extract error message + top N stack frames from an unknown error.
* Use when the error flows to the model as a tool_result — full stack
* traces are ~500-2000 chars of mostly-irrelevant internal frames and
* waste context tokens. Keep the full stack in debug logs instead.
*/
export function shortErrorStack(e: unknown, maxFrames = 5): string {
if (!(e instanceof Error)) return String(e)
if (!e.stack) return e.message
// V8/Bun stack format: "Name: message\n at frame1\n at frame2..."
// First line is the message; subsequent " at " lines are frames.
const lines = e.stack.split('\n')
const header = lines[0] ?? e.message
const frames = lines.slice(1).filter(l => l.trim().startsWith('at '))
if (frames.length <= maxFrames) return e.stack
return [header, ...frames.slice(0, maxFrames)].join('\n')
}
/**
* True if the error means the path is missing, inaccessible, or
* structurally unreachable — use in catch blocks after fs operations to
* distinguish expected "nothing there / no access" from unexpected errors.
*
* Covers:
* ENOENT — path does not exist
* EACCES — permission denied
* EPERM — operation not permitted
* ENOTDIR — a path component is not a directory (e.g. a file named
* `.claude` exists where a directory is expected)
* ELOOP — too many symlink levels (circular symlinks)
*/
export function isFsInaccessible(e: unknown): e is NodeJS.ErrnoException {
const code = getErrnoCode(e)
return (
code === 'ENOENT' ||
code === 'EACCES' ||
code === 'EPERM' ||
code === 'ENOTDIR' ||
code === 'ELOOP'
)
}
export type AxiosErrorKind =
| 'auth' // 401/403 — caller typically sets skipRetry
| 'timeout' // ECONNABORTED
| 'network' // ECONNREFUSED/ENOTFOUND
| 'http' // other axios error (may have status)
| 'other' // not an axios error
/**
* Classify a caught error from an axios request into one of a few buckets.
* Replaces the ~20-line isAxiosError → 401/403 → ECONNABORTED → ECONNREFUSED
* chain duplicated across sync-style services (settingsSync, policyLimits,
* remoteManagedSettings, teamMemorySync).
*
* Checks the `.isAxiosError` marker property directly (same as
* axios.isAxiosError()) to keep this module dependency-free.
*/
export function classifyAxiosError(e: unknown): {
kind: AxiosErrorKind
status?: number
message: string
} {
const message = errorMessage(e)
if (
!e ||
typeof e !== 'object' ||
!('isAxiosError' in e) ||
!e.isAxiosError
) {
return { kind: 'other', message }
}
const err = e as {
response?: { status?: number }
code?: string
}
const status = err.response?.status
if (status === 401 || status === 403) return { kind: 'auth', status, message }
if (err.code === 'ECONNABORTED') return { kind: 'timeout', status, message }
if (err.code === 'ECONNREFUSED' || err.code === 'ENOTFOUND') {
return { kind: 'network', status, message }
}
return { kind: 'http', status, message }
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/up/claude-code-source-code.git
git@gitee.com:up/claude-code-source-code.git
up
claude-code-source-code
claude-code-source-code
main
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /