mirror of
https://github.com/sst/opencode.git
synced 2025-12-23 10:11:41 +00:00
ignore: better error logging
This commit is contained in:
parent
ad5f209dc8
commit
122944fab8
1 changed files with 8 additions and 1 deletions
|
|
@ -83,6 +83,13 @@ export namespace Log {
|
|||
await Promise.all(filesToDelete.map((file) => fs.unlink(file).catch(() => {})))
|
||||
}
|
||||
|
||||
function formatError(error: Error, depth = 0): string {
|
||||
const result = error.message
|
||||
return error.cause instanceof Error && depth < 10
|
||||
? result + " Caused by: " + formatError(error.cause, depth + 1)
|
||||
: result
|
||||
}
|
||||
|
||||
let last = Date.now()
|
||||
export function create(tags?: Record<string, any>) {
|
||||
tags = tags || {}
|
||||
|
|
@ -103,7 +110,7 @@ export namespace Log {
|
|||
.filter(([_, value]) => value !== undefined && value !== null)
|
||||
.map(([key, value]) => {
|
||||
const prefix = `${key}=`
|
||||
if (value instanceof Error) return prefix + value.message
|
||||
if (value instanceof Error) return prefix + formatError(value)
|
||||
if (typeof value === "object") return prefix + JSON.stringify(value)
|
||||
return prefix + value
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue