fix(dbal): render CLI plain text output properly instead of escaped JSON

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-18 23:41:30 +00:00
parent f09c5e7ac3
commit 7fbece2af5
2 changed files with 15 additions and 7 deletions

View File

@@ -57,12 +57,14 @@ export async function POST(request: NextRequest) {
env: env as NodeJS.ProcessEnv,
})
// Try to parse stdout as JSON
// Try to parse stdout as JSON, otherwise return as structured text
let data: unknown
try {
data = JSON.parse(stdout)
} catch {
data = stdout || stderr || '(no output)'
const output = (stdout || '').trim()
const err = (stderr || '').trim()
data = { output: output || err || '(no output)' }
}
return NextResponse.json({
@@ -78,7 +80,7 @@ export async function POST(request: NextRequest) {
let data: unknown
if (error.stdout) {
try { data = JSON.parse(error.stdout) } catch { data = error.stdout }
try { data = JSON.parse(error.stdout) } catch { data = { output: error.stdout.trim() } }
}
return NextResponse.json({

View File

@@ -135,6 +135,10 @@ function syntaxHighlight(json: string): string {
)
}
function isPlainOutput(data: unknown): boolean {
return typeof data === 'object' && data !== null && 'output' in data && typeof (data as { output: unknown }).output === 'string'
}
function loadHistory(): QueryHistoryEntry[] {
if (typeof window === 'undefined') return []
try {
@@ -505,10 +509,12 @@ export function QueryConsole() {
{response.status} {response.statusText}
</span>
</div>
<pre
className={styles.responsePre}
dangerouslySetInnerHTML={{ __html: syntaxHighlight(JSON.stringify(response.data, null, 2)) }}
/>
<pre className={styles.responsePre}>
{isPlainOutput(response.data)
? (response.data as { output: string }).output
: <span dangerouslySetInnerHTML={{ __html: syntaxHighlight(JSON.stringify(response.data, null, 2)) }} />
}
</pre>
</div>
)}
</div>