Skip to content

Commit d77a185

Browse files
committed
update logging
1 parent d2aaefc commit d77a185

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

cli/src/hooks/use-send-message.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useCallback, useEffect, useRef } from 'react'
33
import { getCodebuffClient, formatToolOutput } from '../utils/codebuff-client'
44
import { shouldHideAgent } from '../utils/constants'
55
import { createValidationErrorBlocks } from '../utils/create-validation-error-blocks'
6+
import { getErrorObject } from '../utils/error'
67
import { formatTimestamp } from '../utils/helpers'
78
import { loadAgentDefinitions } from '../utils/load-agent-definitions'
89
import { getLoadedAgentsData } from '../utils/local-agent-registry'
@@ -1318,7 +1319,10 @@ export const useSendMessage = ({
13181319
} catch (error) {
13191320
const isAborted = error instanceof Error && error.name === 'AbortError'
13201321

1321-
logger.error(error, 'SDK client.run() failed')
1322+
logger.error(
1323+
{ error: getErrorObject(error) },
1324+
'SDK client.run() failed',
1325+
)
13221326
setIsStreaming(false)
13231327
setCanProcessQueue(true)
13241328
updateChainInProgress(false)

cli/src/utils/error.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
export type ErrorOr<T, E extends ErrorObject = ErrorObject> =
2+
| Success<T>
3+
| Failure<E>
4+
5+
export type Success<T> = {
6+
success: true
7+
value: T
8+
}
9+
10+
export type Failure<E extends ErrorObject = ErrorObject> = {
11+
success: false
12+
error: E
13+
}
14+
15+
export type ErrorObject = {
16+
name: string
17+
message: string
18+
stack?: string
19+
}
20+
21+
export function success<T>(value: T): Success<T> {
22+
return {
23+
success: true,
24+
value,
25+
}
26+
}
27+
28+
export function failure(error: any): Failure<ErrorObject> {
29+
return {
30+
success: false,
31+
error: getErrorObject(error),
32+
}
33+
}
34+
35+
export function getErrorObject(error: any): ErrorObject {
36+
if (error instanceof Error) {
37+
return {
38+
name: error.name,
39+
message: error.message,
40+
stack: error.stack,
41+
}
42+
}
43+
44+
return {
45+
name: 'Error',
46+
message: `${error}`,
47+
}
48+
}

0 commit comments

Comments
 (0)