Skip to content

Commit eb553f5

Browse files
authored
fix: ensure sqlite migration logs to stderr instead of stdout (#13691)
1 parent d1482e1 commit eb553f5

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

packages/opencode/src/index.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,14 @@ const cli = yargs(hideBin(process.argv))
8282

8383
const marker = path.join(Global.Path.data, "opencode.db")
8484
if (!(await Bun.file(marker).exists())) {
85-
console.log("Performing one time database migration, may take a few minutes...")
86-
const tty = process.stdout.isTTY
85+
const tty = process.stderr.isTTY
86+
process.stderr.write("Performing one time database migration, may take a few minutes..." + EOL)
8787
const width = 36
8888
const orange = "\x1b[38;5;214m"
8989
const muted = "\x1b[0;2m"
9090
const reset = "\x1b[0m"
9191
let last = -1
92-
if (tty) process.stdout.write("\x1b[?25l")
92+
if (tty) process.stderr.write("\x1b[?25l")
9393
try {
9494
await JsonMigration.run(Database.Client().$client, {
9595
progress: (event) => {
@@ -99,22 +99,22 @@ const cli = yargs(hideBin(process.argv))
9999
if (tty) {
100100
const fill = Math.round((percent / 100) * width)
101101
const bar = `${"■".repeat(fill)}${"・".repeat(width - fill)}`
102-
process.stdout.write(
102+
process.stderr.write(
103103
`\r${orange}${bar} ${percent.toString().padStart(3)}%${reset} ${muted}${event.label.padEnd(12)} ${event.current}/${event.total}${reset}`,
104104
)
105-
if (event.current === event.total) process.stdout.write("\n")
105+
if (event.current === event.total) process.stderr.write("\n")
106106
} else {
107-
console.log(`sqlite-migration:${percent}`)
107+
process.stderr.write(`sqlite-migration:${percent}${EOL}`)
108108
}
109109
},
110110
})
111111
} finally {
112-
if (tty) process.stdout.write("\x1b[?25h")
112+
if (tty) process.stderr.write("\x1b[?25h")
113113
else {
114-
console.log(`sqlite-migration:done`)
114+
process.stderr.write(`sqlite-migration:done${EOL}`)
115115
}
116116
}
117-
console.log("Database migration complete.")
117+
process.stderr.write("Database migration complete." + EOL)
118118
}
119119
})
120120
.usage("\n" + UI.logo())
@@ -190,7 +190,7 @@ try {
190190
if (formatted) UI.error(formatted)
191191
if (formatted === undefined) {
192192
UI.error("Unexpected error, check log file at " + Log.file() + " for more details" + EOL)
193-
console.error(e instanceof Error ? e.message : String(e))
193+
process.stderr.write((e instanceof Error ? e.message : String(e)) + EOL)
194194
}
195195
process.exitCode = 1
196196
} finally {

0 commit comments

Comments
 (0)