MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / formatError

Function formatError

source code/utils/toolErrors.ts:7–24  ·  view source on GitHub ↗
(error: unknown)

Source from the content-addressed store, hash-verified

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

Callers 4

runPostToolUseHooksFunction · 0.85
runPreToolUseHooksFunction · 0.85

Calls 1

getErrorPartsFunction · 0.85

Tested by

no test coverage detected