MCPcopy Index your code
hub / github.com/codeaashu/claude-code / formatError

Function formatError

src/utils/toolErrors.ts:5–22  ·  view source on GitHub ↗
(error: unknown)

Source from the content-addressed store, hash-verified

3import { INTERRUPT_MESSAGE_FOR_TOOL_USE } from './messages.js'
4
5export function formatError(error: unknown): string {
6 if (error instanceof AbortError) {
7 return error.message || INTERRUPT_MESSAGE_FOR_TOOL_USE
8 }
9 if (!(error instanceof Error)) {
10 return String(error)
11 }
12 const parts = getErrorParts(error)
13 const fullMessage =
14 parts.filter(Boolean).join('\n').trim() || 'Command failed with no output'
15 if (fullMessage.length <= 10000) {
16 return fullMessage
17 }
18 const halfLength = 5000
19 const start = fullMessage.slice(0, halfLength)
20 const end = fullMessage.slice(-halfLength)
21 return `${start}\n\n... [${fullMessage.length - 10000} characters truncated] ...\n\n${end}`
22}
23
24export function getErrorParts(error: Error): string[] {
25 if (error instanceof ShellError) {

Callers 4

runPostToolUseHooksFunction · 0.85
runPreToolUseHooksFunction · 0.85

Calls 1

getErrorPartsFunction · 0.85

Tested by

no test coverage detected