feat(query): jump to PostgreSQL error position from result messages

This commit is contained in:
amwps290 authored and GitHub committed 2026-09-15 17:39:59 +08:00
1 parent 571fc07d85
commit 5a0e74eec6
36 files changed
+2079 -23

No files matched your search

+52
View File
@@ -230,6 +230,20 @@ describe("backend error translation", () => {
expect(sanitizeBackendErrorMessage(message)).toBe(message);
});
test("strips the SQL error-position transport suffix from raw messages", () => {
const message = 'ERROR: relation "missing" does not exist\nDBX_SQL_ERROR_POSITION:15';
const expected = 'ERROR: relation "missing" does not exist';
expect(sanitizeBackendErrorMessage(message)).toBe(expected);
expect(formatError(new Error(message))).toBe(expected);
});
test("strips the position suffix that precedes appended context text", () => {
const message = "ERROR: boom\nDBX_SQL_ERROR_POSITION:7; cleanup failed";
expect(sanitizeBackendErrorMessage(message)).toBe("ERROR: boom; cleanup failed");
});
test("normalizes Error and structural message objects before translation", () => {
const t = translatorFor("zh-CN");
const message = "file does not exist: /tmp/missing.sqlite";
@@ -327,6 +341,44 @@ describe("backend error translation", () => {
).toBeNull();
});
test("accepts an optional driver-reported error position", () => {
const error = normalizeBackendError({
version: 1,
code: "DBX-JDBC-4001",
messageKey: "backendErrors.jdbc.sqlFailed",
messageParams: { stage: "execute" },
source: "jdbcAgent",
operationOutcome: "unknown",
detail: 'ERROR: relation "missing" does not exist',
errorPosition: { line: 2, column: 6, offset: 12 },
});
expect(error?.errorPosition).toEqual({ line: 2, column: 6, offset: 12 });
const t = translatorFor("zh-CN");
expect(translateBackendError(t, error)).toBe(`${t("backendErrors.jdbc.sqlFailed", { stage: "execute" })}\n\nERROR: relation "missing" does not exist`);
});
test.each([
["zero line", { line: 0, column: 1, offset: 0 }],
["negative column", { line: 1, column: -1, offset: 0 }],
["non-integer offset", { line: 1, column: 1, offset: 1.5 }],
["string line", { line: "1", column: 1, offset: 0 }],
["array position", [1, 1, 0]],
])("rejects a malformed error position with %s", (_name, errorPosition) => {
expect(
normalizeBackendError({
version: 1,
code: "DBX-JDBC-4001",
messageKey: "backendErrors.jdbc.sqlFailed",
messageParams: { stage: "execute" },
source: "jdbcAgent",
operationOutcome: "unknown",
errorPosition,
}),
).toBeNull();
});
test("accepts unknown compatibility sources and extensible origins", () => {
const error = normalizeBackendError({
version: 1,
+3
View File
@@ -1311,6 +1311,8 @@ export default withEnglishFallback({
queryTimeoutError: "Sorğunun vaxt limiti bitdi ({seconds}s). Verilənlər bazası əlaqəsinin işlək olub-olmadığını yoxlayın.",
changeConnectionTimeout: "Əlaqənin vaxt limitini dəyiş",
changeQueryTimeout: "Sorğunun vaxt limitini dəyiş",
locateError: "Xətanı tap ({line}. sətir, {column}. sütun)",
errorPositionUnavailable: "Xəta mövqeyi redaktorun cari məzmununa uyğun gəlmir, ona görə də tapıla bilmir.",
connectionMayBeLost: "Əlaqə kəsilmiş ola bilər. Məlumatları yeniləyin və yenidən cəhd edin.",
showResultsPane: "Nəticələri göstər",
hideResultsPane: "Nəticələri gizlət",
@@ -1655,6 +1657,7 @@ export default withEnglishFallback({
returnedTable: "{count} sütunlu nəticə cədvəli qaytarıldı",
noTable: "Nəticə cədvəli qaytarılmadı",
noSql: "SQL mövcud deyil",
lineColumn: "{line}. sətir, {column}. sütun",
navigationHint: "SQL-ə önbaxış üçün sətrə klikləyin; redaktorda ona keçmək üçün iki dəfə klikləyin.",
recoveryPrompt: "#{statement} əmri uğursuz oldu; {count} əmr işlədilmədi.",
stop: "Dayandır",
+3
View File
@@ -1442,6 +1442,8 @@ export default {
queryTimeoutError: "Query timed out ({seconds}s). Check whether the database connection is healthy.",
changeConnectionTimeout: "Change connection timeout",
changeQueryTimeout: "Change query timeout",
locateError: "Locate error (line {line}, col {column})",
errorPositionUnavailable: "The error position no longer matches the editor content, so it cannot be located.",
connectionMayBeLost: "The connection may have been lost. Refresh data and try again.",
showResultsPane: "Show results",
hideResultsPane: "Hide results",
@@ -1786,6 +1788,7 @@ export default {
returnedTable: "Returned a {count}-column result table",
noTable: "No result table returned",
noSql: "SQL unavailable",
lineColumn: "line {line}, col {column}",
navigationHint: "Click a row to preview its SQL; double-click to focus it in the editor.",
recoveryPrompt: "Statement #{statement} failed; {count} statements were not run.",
stop: "Stop",
+3
View File
@@ -1412,6 +1412,8 @@ export default withEnglishFallback({
queryTimeoutError: "La consulta agotó el tiempo ({seconds}s). Comprueba la conexión a la base de datos.",
changeConnectionTimeout: "Cambiar tiempo de espera de conexión",
changeQueryTimeout: "Cambiar tiempo de espera de consulta",
locateError: "Localizar error (línea {line}, columna {column})",
errorPositionUnavailable: "La posición del error ya no coincide con el contenido del editor, por lo que no se puede localizar.",
connectionMayBeLost: "Es posible que la conexión se haya perdido. Actualiza los datos e inténtalo de nuevo.",
showResultsPane: "Mostrar resultados",
hideResultsPane: "Ocultar resultados",
@@ -1709,6 +1711,7 @@ export default withEnglishFallback({
returnedTable: "Devolvió una tabla de resultados de {count} columnas",
noTable: "No se devolvió ninguna tabla de resultados",
noSql: "SQL no disponible",
lineColumn: "línea {line}, columna {column}",
navigationHint: "Haz clic para previsualizar el SQL; haz doble clic para enfocarlo en el editor.",
recoveryPrompt: "Falló la sentencia #{statement}; no se ejecutaron {count} sentencias.",
stop: "Detener",
+3
View File
@@ -1410,6 +1410,8 @@ export default withEnglishFallback({
queryTimeoutError: "Timeout della query ({seconds}s). Verifica se la connessione al database è integra.",
changeConnectionTimeout: "Modifica timeout connessione",
changeQueryTimeout: "Modifica timeout query",
locateError: "Individua errore (riga {line}, colonna {column})",
errorPositionUnavailable: "La posizione dell'errore non corrisponde più al contenuto dell'editor, quindi non è possibile individuarla.",
connectionMayBeLost: "La connessione potrebbe essere andata perduta. Aggiorna i dati e riprova.",
showResultsPane: "Mostra risultati",
hideResultsPane: "Nascondi risultati",
@@ -1707,6 +1709,7 @@ export default withEnglishFallback({
returnedTable: "Restituita una tabella con {count} colonne",
noTable: "Nessuna tabella restituita",
noSql: "SQL non disponibile",
lineColumn: "riga {line}, colonna {column}",
navigationHint: "Fai clic per visualizzare l'SQL; fai doppio clic per selezionarlo nell'editor.",
recoveryPrompt: "L'istruzione #{statement} non è riuscita; {count} istruzioni non sono state eseguite.",
stop: "Interrompi",
+3
View File
@@ -1431,6 +1431,8 @@ export default withEnglishFallback({
queryTimeoutError: "クエリがタイムアウトしました({seconds}秒)。データベース接続が正常か確認してください。",
changeConnectionTimeout: "接続タイムアウトを変更",
changeQueryTimeout: "クエリタイムアウトを変更",
locateError: "エラー位置へ移動({line} 行目 {column} 桁目)",
errorPositionUnavailable: "エラー位置が現在のエディター内容と一致しないため、位置を特定できません。",
connectionMayBeLost: "接続が失われた可能性があります。データを更新して再試行してください。",
showResultsPane: "結果を表示",
hideResultsPane: "結果を非表示",
@@ -1729,6 +1731,7 @@ export default withEnglishFallback({
returnedTable: "{count}列の結果テーブルを返しました",
noTable: "結果テーブルは返されませんでした",
noSql: "SQLを取得できません",
lineColumn: "{line} 行目 {column} 桁目",
navigationHint: "クリックでSQLをプレビューし、ダブルクリックでエディター内を選択します。",
recoveryPrompt: "ステートメント #{statement} が失敗し、残り {count} 件は未実行です。",
stop: "停止",
+3
View File
@@ -1332,6 +1332,8 @@ export default withEnglishFallback({
queryTimeoutError: "쿼리 시간 초과 ({seconds}초). 데이터베이스 연결이 정상인지 확인하세요.",
changeConnectionTimeout: "연결 제한 시간 변경",
changeQueryTimeout: "쿼리 제한 시간 변경",
locateError: "오류 위치로 이동 ({line}행 {column}열)",
errorPositionUnavailable: "오류 위치가 현재 편집기 내용과 일치하지 않아 위치를 찾을 수 없습니다.",
connectionMayBeLost: "연결이 끊어졌을 수 있습니다. 데이터를 새로고침하고 다시 시도하세요.",
showResultsPane: "결과 표시",
hideResultsPane: "결과 숨기기",
@@ -1658,6 +1660,7 @@ export default withEnglishFallback({
returnedTable: "{count}열 결과 테이블을 반환했습니다",
noTable: "반환된 결과 테이블이 없습니다",
noSql: "SQL을 가져올 수 없습니다",
lineColumn: "{line}행 {column}열",
navigationHint: "행을 클릭하여 SQL을 미리 보고 두 번 클릭하여 편집기에서 선택하세요.",
recoveryPrompt: "구문 #{statement} 실행에 실패하여 나머지 {count}개 구문이 실행되지 않았습니다.",
stop: "중지",
+3
View File
@@ -1411,6 +1411,8 @@ export default withEnglishFallback({
queryTimeoutError: "A consulta expirou ({seconds}s). Verifique se a conexão com o banco de dados está saudável.",
changeConnectionTimeout: "Alterar tempo limite da conexão",
changeQueryTimeout: "Alterar tempo limite da consulta",
locateError: "Localizar erro (linha {line}, coluna {column})",
errorPositionUnavailable: "A posição do erro não corresponde mais ao conteúdo do editor, portanto não é possível localizá-la.",
connectionMayBeLost: "A conexão pode ter sido perdida. Atualize os dados e tente novamente.",
showResultsPane: "Mostrar resultados",
hideResultsPane: "Ocultar resultados",
@@ -1709,6 +1711,7 @@ export default withEnglishFallback({
returnedTable: "Retornou uma tabela de resultado com {count} colunas",
noTable: "Nenhuma tabela de resultado retornada",
noSql: "SQL indisponível",
lineColumn: "linha {line}, coluna {column}",
navigationHint: "Clique para visualizar o SQL; clique duas vezes para selecioná-lo no editor.",
recoveryPrompt: "A instrução #{statement} falhou; {count} instruções não foram executadas.",
stop: "Parar",
+3
View File
@@ -1313,6 +1313,8 @@ export default withEnglishFallback({
queryTimeoutError: "Sorgu zaman aşımına uğradı ({seconds} sn). Veritabanı bağlantısının sağlıklı olup olmadığını denetleyin.",
changeConnectionTimeout: "Bağlantı zaman aşımını değiştir",
changeQueryTimeout: "Sorgu zaman aşımını değiştir",
locateError: "Hatayı bul ({line}. satır, {column}. sütun)",
errorPositionUnavailable: "Hata konumu düzenleyicinin geçerli içeriğiyle eşleşmediği için bulunamıyor.",
connectionMayBeLost: "Bağlantı kopmuş olabilir. Verileri yenileyip tekrar deneyin.",
showResultsPane: "Sonuçları göster",
hideResultsPane: "Sonuçları gizle",
@@ -1656,6 +1658,7 @@ export default withEnglishFallback({
returnedTable: "{count} sütunlu bir sonuç tablosu döndürdü",
noTable: "Sonuç tablosu döndürülmedi",
noSql: "SQL kullanılamıyor",
lineColumn: "{line}. satır, {column}. sütun",
navigationHint: "SQL'ini önizlemek için bir satıra tıklayın; düzenleyicide odaklamak için çift tıklayın.",
recoveryPrompt: "#{statement} numaralı ifade başarısız oldu; {count} ifade çalıştırılmadı.",
stop: "Durdur",
+3
View File
@@ -1357,6 +1357,8 @@ export default withEnglishFallback({
queryTimeoutError: "查询超时 ({seconds}s),请检查数据库连接是否正常",
changeConnectionTimeout: "修改超时时间",
changeQueryTimeout: "修改查询超时时间",
locateError: "定位错误(第 {line} 行,第 {column} 列)",
errorPositionUnavailable: "错误位置与当前编辑器内容不一致,无法定位。",
connectionMayBeLost: "连接可能已断开,请刷新数据重试",
showResultsPane: "显示结果",
hideResultsPane: "收起",
@@ -1701,6 +1703,7 @@ export default withEnglishFallback({
returnedTable: "返回 {count} 列结果表",
noTable: "未返回结果表",
noSql: "无法获取 SQL",
lineColumn: "第 {line} 行,第 {column} 列",
navigationHint: "单击预览对应 SQL,双击在编辑器中聚焦并选中。",
recoveryPrompt: "语句 #{statement} 执行失败,剩余 {count} 条未执行。",
stop: "停止",
+3
View File
@@ -1410,6 +1410,8 @@ export default withEnglishFallback({
queryTimeoutError: "查詢逾時 ({seconds}s),請檢查資料庫連線是否正常",
changeConnectionTimeout: "修改連線逾時時間",
changeQueryTimeout: "修改查詢逾時時間",
locateError: "定位錯誤(第 {line} 行,第 {column} 列)",
errorPositionUnavailable: "錯誤位置與目前編輯器內容不一致,無法定位。",
connectionMayBeLost: "連線可能已斷開,請重新整理資料重試",
showResultsPane: "顯示結果",
hideResultsPane: "收起結果",
@@ -1708,6 +1710,7 @@ export default withEnglishFallback({
returnedTable: "回傳 {count} 欄的結果表",
noTable: "未回傳結果表",
noSql: "無法取得 SQL",
lineColumn: "第 {line} 行,第 {column} 列",
navigationHint: "按一下預覽 SQL,按兩下在編輯器中聚焦並選取。",
recoveryPrompt: "語句 #{statement} 執行失敗,剩餘 {count} 條未執行。",
stop: "停止",