fix(opencode): display proper session import errors (#36258)
This commit is contained in:
@@ -38,6 +38,17 @@ export function shouldAttachShareAuthHeaders(shareUrl: string, accountBaseUrl: s
|
||||
}
|
||||
}
|
||||
|
||||
export function formatImportFileError(file: string, error: FSUtil.Error) {
|
||||
if (error._tag === "PlatformError") {
|
||||
if (error.reason._tag === "NotFound") return `File not found: ${file}`
|
||||
if (error.reason._tag === "PermissionDenied") return `Failed to read file: Permission denied`
|
||||
return `Failed to read file: ${error.message}`
|
||||
}
|
||||
|
||||
const detail = error.cause instanceof Error ? error.cause.message : error.message
|
||||
return `Invalid JSON in ${file}: ${detail}`
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform ShareNext API response (flat array) into the nested structure for local file storage.
|
||||
*
|
||||
@@ -154,14 +165,9 @@ const runImport = Effect.fn("Cli.import.body")(function* (file: string, ctx: Ins
|
||||
|
||||
exportData = transformed
|
||||
} else {
|
||||
exportData = (yield* fs.readJson(file).pipe(Effect.orElseSucceed(() => undefined))) as
|
||||
| NonNullable<typeof exportData>
|
||||
| undefined
|
||||
if (!exportData) {
|
||||
process.stdout.write(`File not found: ${file}`)
|
||||
process.stdout.write(EOL)
|
||||
return
|
||||
}
|
||||
exportData = (yield* fs
|
||||
.readJson(file)
|
||||
.pipe(Effect.mapError((error) => new CliError({ message: formatImportFileError(file, error) })))) as ExportData
|
||||
}
|
||||
|
||||
if (!exportData) {
|
||||
|
||||
Reference in New Issue
Block a user