mirror of
https://github.com/sst/opencode.git
synced 2025-12-23 10:11:41 +00:00
Merge 81059b123e into 83397ebde2
This commit is contained in:
commit
cdbba5482a
4 changed files with 53 additions and 13 deletions
|
|
@ -64,13 +64,27 @@ async function getAllSessions(): Promise<Session.Info[]> {
|
|||
const sessions: Session.Info[] = []
|
||||
|
||||
const projectKeys = await Storage.list(["project"])
|
||||
const projects = await Promise.all(projectKeys.map((key) => Storage.read<Project.Info>(key)))
|
||||
const projects = await Promise.all(
|
||||
projectKeys.map((key) =>
|
||||
Storage.read<Project.Info>(key).catch((e) => {
|
||||
console.error(`Skipping corrupted project ${key.join("/")}:`, e)
|
||||
return null
|
||||
}),
|
||||
),
|
||||
)
|
||||
|
||||
for (const project of projects) {
|
||||
if (!project) continue
|
||||
|
||||
const sessionKeys = await Storage.list(["session", project.id])
|
||||
const projectSessions = await Promise.all(sessionKeys.map((key) => Storage.read<Session.Info>(key)))
|
||||
const projectSessions = await Promise.all(
|
||||
sessionKeys.map((key) =>
|
||||
Storage.read<Session.Info>(key).catch((e) => {
|
||||
console.error(`Skipping corrupted session ${key.join("/")}:`, e)
|
||||
return null
|
||||
}),
|
||||
),
|
||||
)
|
||||
|
||||
for (const session of projectSessions) {
|
||||
if (session) {
|
||||
|
|
|
|||
|
|
@ -67,9 +67,13 @@ export const prettier: Info = {
|
|||
async enabled() {
|
||||
const items = await Filesystem.findUp("package.json", Instance.directory, Instance.worktree)
|
||||
for (const item of items) {
|
||||
const json = await Bun.file(item).json()
|
||||
if (json.dependencies?.prettier) return true
|
||||
if (json.devDependencies?.prettier) return true
|
||||
try {
|
||||
const json = await Bun.file(item).json()
|
||||
if (json.dependencies?.prettier) return true
|
||||
if (json.devDependencies?.prettier) return true
|
||||
} catch (e) {
|
||||
console.error(`Skipping corrupted package.json ${item}:`, e)
|
||||
}
|
||||
}
|
||||
return false
|
||||
},
|
||||
|
|
|
|||
|
|
@ -543,10 +543,14 @@ export namespace MessageV2 {
|
|||
export const stream = fn(Identifier.schema("session"), async function* (sessionID) {
|
||||
const list = await Array.fromAsync(await Storage.list(["message", sessionID]))
|
||||
for (let i = list.length - 1; i >= 0; i--) {
|
||||
yield await get({
|
||||
sessionID,
|
||||
messageID: list[i][2],
|
||||
})
|
||||
try {
|
||||
yield await get({
|
||||
sessionID,
|
||||
messageID: list[i][2],
|
||||
})
|
||||
} catch (e) {
|
||||
console.error(`Skipping corrupted message ${list[i][2]}:`, e)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
|
@ -609,7 +613,7 @@ export namespace MessageV2 {
|
|||
},
|
||||
{ cause: e },
|
||||
).toObject()
|
||||
case APICallError.isInstance(e):
|
||||
case APICallError.isInstance(e): {
|
||||
const message = iife(() => {
|
||||
let msg = e.message
|
||||
if (msg === "") {
|
||||
|
|
@ -650,6 +654,7 @@ export namespace MessageV2 {
|
|||
},
|
||||
{ cause: e },
|
||||
).toObject()
|
||||
}
|
||||
case e instanceof Error:
|
||||
return new NamedError.Unknown({ message: e.toString() }, { cause: e }).toObject()
|
||||
default:
|
||||
|
|
|
|||
|
|
@ -170,8 +170,15 @@ export namespace Storage {
|
|||
const target = path.join(dir, ...key) + ".json"
|
||||
return withErrorHandling(async () => {
|
||||
using _ = await Lock.read(target)
|
||||
const result = await Bun.file(target).json()
|
||||
return result as T
|
||||
try {
|
||||
const result = await Bun.file(target).json()
|
||||
return result as T
|
||||
} catch (e) {
|
||||
if (e instanceof SyntaxError) {
|
||||
throw new Error(`Failed to parse JSON in file ${target}: ${e.message}`)
|
||||
}
|
||||
throw e
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -180,7 +187,17 @@ export namespace Storage {
|
|||
const target = path.join(dir, ...key) + ".json"
|
||||
return withErrorHandling(async () => {
|
||||
using _ = await Lock.write(target)
|
||||
const content = await Bun.file(target).json()
|
||||
let content: T
|
||||
try {
|
||||
content = await Bun.file(target).json()
|
||||
} catch (e) {
|
||||
if (e instanceof SyntaxError) {
|
||||
console.error(`Corrupted JSON in ${target}, resetting to empty object:`, e.message)
|
||||
content = {} as T
|
||||
} else {
|
||||
throw e
|
||||
}
|
||||
}
|
||||
fn(content)
|
||||
await Bun.write(target, JSON.stringify(content, null, 2))
|
||||
return content as T
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue