fix: ensure sqlite migration logs to stderr instead of stdout (#13691)
This commit is contained in:
@@ -82,14 +82,14 @@ const cli = yargs(hideBin(process.argv))
|
|||||||
|
|
||||||
const marker = path.join(Global.Path.data, "opencode.db")
|
const marker = path.join(Global.Path.data, "opencode.db")
|
||||||
if (!(await Bun.file(marker).exists())) {
|
if (!(await Bun.file(marker).exists())) {
|
||||||
console.log("Performing one time database migration, may take a few minutes...")
|
const tty = process.stderr.isTTY
|
||||||
const tty = process.stdout.isTTY
|
process.stderr.write("Performing one time database migration, may take a few minutes..." + EOL)
|
||||||
const width = 36
|
const width = 36
|
||||||
const orange = "\x1b[38;5;214m"
|
const orange = "\x1b[38;5;214m"
|
||||||
const muted = "\x1b[0;2m"
|
const muted = "\x1b[0;2m"
|
||||||
const reset = "\x1b[0m"
|
const reset = "\x1b[0m"
|
||||||
let last = -1
|
let last = -1
|
||||||
if (tty) process.stdout.write("\x1b[?25l")
|
if (tty) process.stderr.write("\x1b[?25l")
|
||||||
try {
|
try {
|
||||||
await JsonMigration.run(Database.Client().$client, {
|
await JsonMigration.run(Database.Client().$client, {
|
||||||
progress: (event) => {
|
progress: (event) => {
|
||||||
@@ -99,22 +99,22 @@ const cli = yargs(hideBin(process.argv))
|
|||||||
if (tty) {
|
if (tty) {
|
||||||
const fill = Math.round((percent / 100) * width)
|
const fill = Math.round((percent / 100) * width)
|
||||||
const bar = `${"■".repeat(fill)}${"・".repeat(width - fill)}`
|
const bar = `${"■".repeat(fill)}${"・".repeat(width - fill)}`
|
||||||
process.stdout.write(
|
process.stderr.write(
|
||||||
`\r${orange}${bar} ${percent.toString().padStart(3)}%${reset} ${muted}${event.label.padEnd(12)} ${event.current}/${event.total}${reset}`,
|
`\r${orange}${bar} ${percent.toString().padStart(3)}%${reset} ${muted}${event.label.padEnd(12)} ${event.current}/${event.total}${reset}`,
|
||||||
)
|
)
|
||||||
if (event.current === event.total) process.stdout.write("\n")
|
if (event.current === event.total) process.stderr.write("\n")
|
||||||
} else {
|
} else {
|
||||||
console.log(`sqlite-migration:${percent}`)
|
process.stderr.write(`sqlite-migration:${percent}${EOL}`)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
} finally {
|
} finally {
|
||||||
if (tty) process.stdout.write("\x1b[?25h")
|
if (tty) process.stderr.write("\x1b[?25h")
|
||||||
else {
|
else {
|
||||||
console.log(`sqlite-migration:done`)
|
process.stderr.write(`sqlite-migration:done${EOL}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log("Database migration complete.")
|
process.stderr.write("Database migration complete." + EOL)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.usage("\n" + UI.logo())
|
.usage("\n" + UI.logo())
|
||||||
@@ -190,7 +190,7 @@ try {
|
|||||||
if (formatted) UI.error(formatted)
|
if (formatted) UI.error(formatted)
|
||||||
if (formatted === undefined) {
|
if (formatted === undefined) {
|
||||||
UI.error("Unexpected error, check log file at " + Log.file() + " for more details" + EOL)
|
UI.error("Unexpected error, check log file at " + Log.file() + " for more details" + EOL)
|
||||||
console.error(e instanceof Error ? e.message : String(e))
|
process.stderr.write((e instanceof Error ? e.message : String(e)) + EOL)
|
||||||
}
|
}
|
||||||
process.exitCode = 1
|
process.exitCode = 1
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
Reference in New Issue
Block a user