qiyu-cli 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +433 -72
- package/dist/cli.js +48 -7
- package/dist/commands/api-notes.js +70 -0
- package/dist/commands/api.js +169 -49
- package/dist/commands/auth.js +151 -29
- package/dist/commands/credentials-source.js +30 -5
- package/dist/commands/db-notes.js +75 -0
- package/dist/commands/db.js +165 -127
- package/dist/commands/query-notes.js +58 -0
- package/dist/commands/query.js +449 -61
- package/dist/commands/skill.js +445 -51
- package/dist/commands/spec-types.js +101 -1
- package/dist/commands/stats.js +160 -33
- package/dist/commands/store-flags.js +18 -0
- package/dist/commands/store-notes.js +38 -0
- package/dist/commands/store-precheck.js +321 -0
- package/dist/commands/store.js +165 -77
- package/dist/commands/sync-notes.js +374 -0
- package/dist/commands/sync-run.js +180 -47
- package/dist/commands/sync.js +232 -127
- package/dist/core/config.js +280 -24
- package/dist/core/credentials.js +38 -4
- package/dist/core/edition.js +1 -1
- package/dist/core/envelope.js +73 -9
- package/dist/core/errors.js +73 -16
- package/dist/core/http.js +175 -54
- package/dist/core/ratelimit.js +5 -1
- package/dist/core/registry/index.js +36 -2
- package/dist/core/registry/params/export.session.check.json +17 -2
- package/dist/core/registry/params/export.session.json +24 -2
- package/dist/core/registry/params/export.session.one.json +10 -2
- package/dist/core/registry/params/export.session.one.message.json +17 -2
- package/dist/core/registry/specs.json +65 -43
- package/dist/core/shell.js +30 -0
- package/dist/core/time.js +1 -1
- package/dist/core/validate.js +21 -2
- package/dist/output.js +215 -29
- package/dist/postinstall.js +14 -5
- package/dist/query/errors.js +145 -45
- package/dist/query/mask.js +1277 -25
- package/dist/query/metric-catalog.js +11 -0
- package/dist/query/native-error.js +189 -0
- package/dist/query/sandbox.js +148 -25
- package/dist/query/table-query.js +36 -5
- package/dist/schedule/install.js +136 -13
- package/dist/skill/check.js +11 -6
- package/dist/skill/detect.js +89 -29
- package/dist/skill/install.js +233 -43
- package/dist/skill/paths.js +54 -0
- package/dist/skill/qiyu/SKILL.md +29 -5
- package/dist/skill/qiyu/errors.md +5 -4
- package/dist/skill/qiyu/protocols.md +57 -5
- package/dist/skill/qiyu/setup.md +6 -2
- package/dist/store/config.js +92 -16
- package/dist/store/duckdb.js +1551 -64
- package/dist/store/object-kinds.js +32 -0
- package/dist/store/retry.js +190 -7
- package/dist/store/schema.js +32 -4
- package/dist/sync/engine.js +439 -77
- package/dist/sync/registry.js +6 -0
- package/dist/sync/state.js +20 -0
- package/dist/sync/tasks/dim.js +23 -14
- package/dist/sync/tasks/knowledge.js +50 -8
- package/dist/sync/tasks/pace.js +27 -0
- package/dist/sync/tasks/pipeline.js +29 -9
- package/dist/sync/tasks/reports.js +176 -49
- package/dist/sync/tasks/sessions.js +88 -21
- package/dist/sync/tasks/tickets.js +59 -8
- package/dist/sync/types.js +60 -1
- package/dist/sync/windowing.js +0 -22
- package/dist/sync/write-contract.js +79 -0
- package/package.json +2 -2
package/dist/query/errors.js
CHANGED
|
@@ -17,7 +17,18 @@
|
|
|
17
17
|
//
|
|
18
18
|
// ⚠️ 分层约束(spec §5.1):不 import `sync/`、`commands/`。`output.ts` 是 CLI 输出层
|
|
19
19
|
// (信封与退出码),不是命令层,可以 import。
|
|
20
|
-
import { fail, sanitizeMessage, stripSqlEcho } from '../output.js';
|
|
20
|
+
import { fail, failCompact, sanitizeMessage, stripSqlEcho, storeInitCommand, syncRunCommand, dbTablesCommand, dbDescribeCommand, querySqlCommand, SQL_ARG_REPLACE_NOTE } from '../output.js';
|
|
21
|
+
import { isLayer2Blocked, duckDbSaysMissingName, isOutOfMemory, isBinderOrCatalogError, isParserError, withoutSqlEcho, stripOomSolutions, } from './native-error.js';
|
|
22
|
+
/**
|
|
23
|
+
* OOM 的可操作 hint(2026-11-05:两处出口共用一份,避免同一成因两种说法)。
|
|
24
|
+
*
|
|
25
|
+
* ⚠️ 不能照抄 DuckDB 报文里的「Possible solutions」:那三条 SET 在只读沙箱里**必然失败**
|
|
26
|
+
* (`lock_configuration=true`,实测报 `configuration has been locked`)—— 建议一串
|
|
27
|
+
* 跑不动的命令比不给建议更糟。给的是本通道真能做的动作。
|
|
28
|
+
*/
|
|
29
|
+
export const OOM_HINT = '缩小时间范围、加过滤条件或减少排序/分组的列再试。'
|
|
30
|
+
+ '⚠️ 只读沙箱锁定了配置,DuckDB 报错里建议的 SET memory_limit / threads 等在这里会以 '
|
|
31
|
+
+ 'configuration has been locked 失败,不要照做';
|
|
21
32
|
/** 候选上限(spec §十一 / brief):超过即截断并加「等」。 */
|
|
22
33
|
const CANDIDATE_LIMIT = 5;
|
|
23
34
|
/** 编辑距离上限:只接受「打错一两个字符」的输入,再远就不是同一个名字了。 */
|
|
@@ -147,12 +158,62 @@ function candidateHint(candidates) {
|
|
|
147
158
|
// DuckDB 的错误消息会**回显 SQL 原文**(`LINE 1: …`),Parser Error 的报错里若恰好含
|
|
148
159
|
// `Referenced column "x" not found` 字样,无锚的正则会把「语法错」误判成「列不存在」。
|
|
149
160
|
// 实测:`SELECT 1 WHERE x = Referenced column "zzz" not found` → 原文是 Parser Error。
|
|
161
|
+
//
|
|
162
|
+
// ⚠️⚠️ **只锚类别前缀还不够**(2026-11-01 审查实测,与 PR #54 的报文回声污染同一形态):
|
|
163
|
+
// 回显区与列值都是**用户写的文本**,里面可以逐字含类别前缀。实测两个假归因:
|
|
164
|
+
// · `Parser Error: …` 的 `LINE 1:` 回显里写 ``SELEC'Binder Error: Referenced table "sessons" not found!'``
|
|
165
|
+
// → 纯**语法错**被报成「表 sessons 不存在」+ 候选 `sessions`(Agent 会去改它没写过的表名);
|
|
166
|
+
// · `SELECT … LIMIT '<值>'` 在 **prepare 期**常量折叠,`Conversion Error: Could not convert
|
|
167
|
+
// string 'Catalog Error: Table with name zzz does not exist!' to INT64 …` —— 值里的类别前缀
|
|
168
|
+
// 让 `TABLE_NAME_RE` 命中,**类型转换错误**被报成「表 zzz 不存在」。
|
|
169
|
+
// 判据因此收进 `native-error.ts` 的 `duckDbSaysMissingName`(**唯一实现点**):先剥 SQL 回显,
|
|
170
|
+
// 再要求 DuckDB **自己那句话在开头** —— 真报文的类别前缀就在报文开头(探针逐字核对:
|
|
171
|
+
// `Catalog Error: Table with name sessons does not exist!`),唯一带包装的是 Parser
|
|
172
|
+
//(`Failed to extract statements: Parser Error:`),而它不在本判据要认的类别里。
|
|
150
173
|
const TABLE_NAME_RE = /Catalog Error: Table with name ([^\s]+) does not exist/;
|
|
151
174
|
const TABLE_REF_RE = /Binder Error: Referenced table "([^"]+)" not found/;
|
|
152
175
|
const COLUMN_NAMED_RE = /Binder Error: Table "[^"]+" does not have a column named "([^"]+)"/;
|
|
153
176
|
const COLUMN_NAME_RE = /Binder Error: Referenced column "([^"]+)" (?:was )?not found/;
|
|
177
|
+
/** 四条的**唯一判定入口**:DuckDB 自己说「表/列不存在」才算(回显/列值里的仿冒串不算)。 */
|
|
178
|
+
function matchMissingName(msg, patterns) {
|
|
179
|
+
for (const p of patterns) {
|
|
180
|
+
const m = duckDbSaysMissingName(msg, p);
|
|
181
|
+
if (m !== null)
|
|
182
|
+
return m;
|
|
183
|
+
}
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* 「声明有而库中无」的成因与对策(**唯一实现**:db tables 的 warning、db describe 的
|
|
188
|
+
* warning、query --table 与 stats fields 的 hint 四个出口共用——同一事实四处拷贝必然漂移,
|
|
189
|
+
* 而 `db describe` 曾经独立写成「未同步或未建库」,两个成因都到不了该分支)。
|
|
190
|
+
*
|
|
191
|
+
* ⚠️ 成因口径经实测收窄(2026-10-29),「未同步」「未建库」两条都到不了这里:
|
|
192
|
+
* · 「未同步」不产生缺表:`store init` 的迁移一次建全部声明表,从未同步的库 25 张声明表
|
|
193
|
+
* 全在(row_count=0,无缺表警告);`sync run` 自身也先调 `store.init()`(sync-run.ts)。
|
|
194
|
+
* · 「未建库」到不了这个分支:`openGuardedSession` 先要求 `schema_version` 存在——库文件
|
|
195
|
+
* 不存在或零表时早已是 `store_not_initialized`(实测)。
|
|
196
|
+
* 能到达的只有两种:① 旧版 CLI 建的库,部分迁移没跑完(store init 会重放
|
|
197
|
+
* `version > MAX(version)` 的迁移,可补建);② 迁移已完成后表被删/损坏(store init
|
|
198
|
+
* 返回 ok 但**不会**重建该表——迁移已跳过;重新同步只会 Catalog Error
|
|
199
|
+
* `Table with name … does not exist`,实测)。
|
|
200
|
+
* 故文案不得承诺「store init 一定能修」,也不得把 Agent 指向「先同步一次」。
|
|
201
|
+
* ⚠️ 「重建库」是**破坏性**动作(CodeRabbit 2026-10-29 major):库中可能有 `db tables`
|
|
202
|
+
* 警告过的「未声明表」,也可能有超出 API 回补窗口的本地历史——删除库文件后,重建 +
|
|
203
|
+
* 重新同步都拿不回来。文案必须要求先备份再删除。
|
|
204
|
+
* ⚠️ 命令必须**指向本次的库**(2026-10-30 真库实测):这些 hint 出现在
|
|
205
|
+
* `--db <自定义路径>` 的输出里,裸 `qiyu store init` 会建**默认库**、原命令仍缺表。
|
|
206
|
+
* 渲染走 `storeInitCommand(path)` / `syncRunCommand(path)`(output.ts 的唯一实现)。
|
|
207
|
+
*/
|
|
208
|
+
export function missingTableCauses(path, profileFlag) {
|
|
209
|
+
return '若为建库未完成(迁移未跑完),运行 ' + storeInitCommand(path) + ' 可补建缺失的迁移;'
|
|
210
|
+
+ '若迁移已完成而表被删或损坏,store init 不会重建该表,重新同步也只会写入失败(缺表)'
|
|
211
|
+
+ '——需重建库:先备份库文件,再删除并重新 ' + storeInitCommand(path) + '、'
|
|
212
|
+
+ syncRunCommand(path, profileFlag)
|
|
213
|
+
+ '(未声明表与超出 API 回补窗口的本地历史无法靠重建恢复,删除前先确认)';
|
|
214
|
+
}
|
|
154
215
|
/** 表不存在的中文消息 + 候选 hint(原生分支与 cause 补算分支共用,裁决 R9)。 */
|
|
155
|
-
function tableNotFound(name, msg, tables) {
|
|
216
|
+
function tableNotFound(name, msg, tables, loc) {
|
|
156
217
|
const candidates = mergeCandidates(
|
|
157
218
|
// 多要一个:只有知道「还有第 6 个」才能决定 hint 末尾加不加「等」。
|
|
158
219
|
suggestNames(name, tables.map((t) => t.name), CANDIDATE_LIMIT + 1),
|
|
@@ -162,11 +223,11 @@ function tableNotFound(name, msg, tables) {
|
|
|
162
223
|
suggestNames(name, nativeCandidates(msg), CANDIDATE_LIMIT + 1));
|
|
163
224
|
return {
|
|
164
225
|
message: `表 ${name} 不存在`,
|
|
165
|
-
hint: candidates.length > 0 ? candidateHint(candidates) : '用 `
|
|
226
|
+
hint: candidates.length > 0 ? candidateHint(candidates) : '用 `' + dbTablesCommand(loc) + '` 查看可用表',
|
|
166
227
|
};
|
|
167
228
|
}
|
|
168
229
|
/** 列不存在的中文消息 + 候选 hint(候选池 = 全部表的全部列名:SQL 不告诉我们 FROM 哪张表)。 */
|
|
169
|
-
function columnNotFound(name, msg, tables) {
|
|
230
|
+
function columnNotFound(name, msg, tables, loc) {
|
|
170
231
|
const allColumns = [...new Set(tables.flatMap((t) => t.columns.map((c) => c.name)))];
|
|
171
232
|
const candidates = mergeCandidates(suggestNames(name, allColumns, CANDIDATE_LIMIT + 1),
|
|
172
233
|
// 同 tableNotFound:原生候选须过相关性闸门(正确性 P2)。
|
|
@@ -175,32 +236,34 @@ function columnNotFound(name, msg, tables) {
|
|
|
175
236
|
message: `列 ${name} 不存在`,
|
|
176
237
|
hint: candidates.length > 0
|
|
177
238
|
? candidateHint(candidates)
|
|
178
|
-
: '用 `
|
|
239
|
+
: '用 `' + dbDescribeCommand('<表>', loc) + '` 查看列清单',
|
|
179
240
|
};
|
|
180
241
|
}
|
|
181
242
|
/**
|
|
182
243
|
* 原文 → 表/列不存在的 { message, hint }(四种形态统一入口)。
|
|
183
244
|
* 不是表/列不存在时返回 null —— 调用方自行决定后续分派。
|
|
184
245
|
*/
|
|
185
|
-
function missingNameFailure(msg, tables) {
|
|
186
|
-
const byTableName =
|
|
246
|
+
function missingNameFailure(msg, tables, loc) {
|
|
247
|
+
const byTableName = matchMissingName(msg, [TABLE_NAME_RE, TABLE_REF_RE]);
|
|
187
248
|
if (byTableName)
|
|
188
|
-
return tableNotFound(byTableName[1], msg, tables);
|
|
189
|
-
const byColumn =
|
|
249
|
+
return tableNotFound(byTableName[1], msg, tables, loc);
|
|
250
|
+
const byColumn = matchMissingName(msg, [COLUMN_NAMED_RE, COLUMN_NAME_RE]);
|
|
190
251
|
if (byColumn)
|
|
191
|
-
return columnNotFound(byColumn[1], msg, tables);
|
|
252
|
+
return columnNotFound(byColumn[1], msg, tables, loc);
|
|
192
253
|
return null;
|
|
193
254
|
}
|
|
194
255
|
/**
|
|
195
256
|
* 原生错误 → QueryFailure(spec §十一 分派表)。
|
|
196
257
|
*
|
|
197
258
|
* 分派顺序有意义:先透传已分类错误,再按原文形态分流。
|
|
198
|
-
* ⚠️ layer2 的判定与 sandbox
|
|
199
|
-
*
|
|
200
|
-
*
|
|
259
|
+
* ⚠️ layer2 的判定与 sandbox **同源**(`query/native-error.ts` 的 `isLayer2Blocked`,
|
|
260
|
+
* 2026-11-01 单一实现点;此前两处各写一份逐字相同的正则):锚类别前缀
|
|
261
|
+
* `Permission Error:` + 特征句,并在判定前剥掉 SQL 回显 —— 只认「配置禁用了文件系统」
|
|
262
|
+
* 的措辞,**不认裸 `Permission Error`**(读库文件本身的 OS 权限错误也带这个前缀,
|
|
263
|
+
* 误报成「已被只读沙箱拦截」会把环境问题说成用法问题)。
|
|
201
264
|
* `retryable` 一律 false:这些都是确定性错误,重试同一个查询只会得到同样的结果。
|
|
202
265
|
*/
|
|
203
|
-
export function classifyDuckDbError(e, tables) {
|
|
266
|
+
export function classifyDuckDbError(e, tables, loc) {
|
|
204
267
|
// ① 已分类错误原样透传(sandbox 的分工:它分类,这里不重新分类)。
|
|
205
268
|
// ⚠️ 唯一例外(裁决 R9):sandbox 在 prepare 期把原生 Catalog/Binder 错误包成
|
|
206
269
|
// `usage`/`query_error` 并把原文挂在 `cause` 上 —— kind/code 仍以 sandbox 为准,
|
|
@@ -220,44 +283,53 @@ export function classifyDuckDbError(e, tables) {
|
|
|
220
283
|
const causeMsg = errorText(classified.cause);
|
|
221
284
|
// 表/列不存在只对 usage 补算(sandbox 的 prepare 期包装;Minor #6 守卫)。
|
|
222
285
|
if (classified.kind === 'usage') {
|
|
223
|
-
const refined = missingNameFailure(causeMsg, tables);
|
|
286
|
+
const refined = missingNameFailure(causeMsg, tables, loc);
|
|
224
287
|
if (refined) {
|
|
225
288
|
f.message = refined.message;
|
|
226
289
|
f.hint = refined.hint;
|
|
227
290
|
}
|
|
228
291
|
}
|
|
229
292
|
// R11:sandbox 的执行期 catch 把 OOM 包成 internal 且(修复后)挂 cause ——
|
|
230
|
-
// message 保持 sandbox 原文,只补可操作 hint
|
|
231
|
-
|
|
232
|
-
|
|
293
|
+
// message 保持 sandbox 原文,只补可操作 hint。⚠️ 原文里那段「Possible solutions」
|
|
294
|
+
// 的 SET 在只读沙箱里必然失败(见 `stripOomSolutions` 与 `OOM_HINT`),必须剥掉。
|
|
295
|
+
if (classified.kind === 'internal' && isOutOfMemory(causeMsg)) {
|
|
296
|
+
f.message = stripOomSolutions(f.message);
|
|
297
|
+
f.hint = OOM_HINT;
|
|
233
298
|
}
|
|
234
299
|
}
|
|
235
300
|
return f;
|
|
236
301
|
}
|
|
237
302
|
const msg = errorText(e);
|
|
238
|
-
// ② layer2 拦截(文件/网络):spec §十一 行 4
|
|
239
|
-
//
|
|
240
|
-
|
|
241
|
-
if (/file system operations are disabled|Cannot access file/i.test(msg)) {
|
|
303
|
+
// ② layer2 拦截(文件/网络):spec §十一 行 4。判据与 sandbox 同源
|
|
304
|
+
// (`native-error.ts` 的 `isLayer2Blocked`,单一实现点;形态与边界见那里)。
|
|
305
|
+
if (isLayer2Blocked(msg)) {
|
|
242
306
|
return {
|
|
243
307
|
kind: 'usage', code: 'sandbox_blocked', retryable: false,
|
|
244
308
|
message: '该语句尝试访问文件或网络,已被只读沙箱拦截',
|
|
245
309
|
};
|
|
246
310
|
}
|
|
247
311
|
// ③ 表/列不存在:spec §十一 行 5(四种原生形态统一走 missingNameFailure)。
|
|
248
|
-
const missing = missingNameFailure(msg, tables);
|
|
312
|
+
const missing = missingNameFailure(msg, tables, loc);
|
|
249
313
|
if (missing) {
|
|
250
314
|
return { kind: 'usage', code: 'query_error', retryable: false, ...missing };
|
|
251
315
|
}
|
|
252
316
|
// ④ SQL 语法错:spec §十一 行 6 —— 中文包装 + 底层原文(原文自带位置信息,保留全部行)。
|
|
253
|
-
|
|
317
|
+
// 判据走唯一实现点(锚开头 + 剥回显):子串判会被列值里那句 `Parser Error` 伪造,
|
|
318
|
+
// 把类型转换错误说成语法错(修法完全不同:改数据 vs 改 SQL)。
|
|
319
|
+
if (isParserError(msg)) {
|
|
254
320
|
return {
|
|
255
321
|
kind: 'usage', code: 'query_error', retryable: false,
|
|
256
322
|
message: `SQL 语法错误:${msg}`,
|
|
257
323
|
};
|
|
258
324
|
}
|
|
259
325
|
// ⑤ 未绑参:spec §十一 行 6(「SQL 语法错 / 未绑参」同归 usage/query_error)。
|
|
260
|
-
|
|
326
|
+
// ⚠️ 实测两件事:① 真报文前缀是 `Invalid Input Error: Expected 1 parameters, but none were
|
|
327
|
+
// supplied`(探针:`conn.run('SELECT ?')`);prepared 路径抛的是另一句
|
|
328
|
+
// `Values were not provided for the following prepared statement parameters`。本 CLI 的
|
|
329
|
+
// 沙箱在 layer1-③ 用 `parameterCount !== params.length` **提前拦下**,所以这一支在
|
|
330
|
+
// 用户 SQL 路径上不可达,是防御支;② 即便如此也**锚开头 + 剥回显** —— 子串判同样可被
|
|
331
|
+
// 回显里那句字面量伪造(与 ③⑥⑦ 同族),假归因不会因为分支不可达就变得无害。
|
|
332
|
+
if (/^\s*Invalid Input Error:\s*Expected \d+ parameters/i.test(withoutSqlEcho(msg))) {
|
|
261
333
|
return {
|
|
262
334
|
kind: 'usage', code: 'query_error', retryable: false,
|
|
263
335
|
message: `SQL 参数个数不匹配:${msg}`,
|
|
@@ -265,8 +337,9 @@ export function classifyDuckDbError(e, tables) {
|
|
|
265
337
|
};
|
|
266
338
|
}
|
|
267
339
|
// ⑥ 其余 Binder / Catalog 错误(函数不存在、类型不匹配等):同样是 SQL 写错了。
|
|
268
|
-
//
|
|
269
|
-
|
|
340
|
+
// 判据走唯一实现点(锚开头 + 剥回显,容忍 `Failed to extract statements: ` 包装):
|
|
341
|
+
// 子串判会被列值/回显里的 `Catalog Error:` 伪造,把类型转换错误说成 SQL 写错。
|
|
342
|
+
if (isBinderOrCatalogError(msg)) {
|
|
270
343
|
return {
|
|
271
344
|
kind: 'usage', code: 'query_error', retryable: false,
|
|
272
345
|
message: `SQL 无法执行:${msg}`,
|
|
@@ -274,11 +347,13 @@ export function classifyDuckDbError(e, tables) {
|
|
|
274
347
|
};
|
|
275
348
|
}
|
|
276
349
|
// ⑦ 内存不足:环境问题,不是 SQL 写错 —— internal + 可操作 hint。
|
|
277
|
-
|
|
350
|
+
// 判据走唯一实现点:子串判会被列值里的 `Out of Memory Error` 伪造,给类型转换错误
|
|
351
|
+
// 补一条「缩小时间范围」的假修法。
|
|
352
|
+
if (isOutOfMemory(msg)) {
|
|
278
353
|
return {
|
|
279
354
|
kind: 'internal', code: 'internal', retryable: false,
|
|
280
|
-
message: `查询内存不足(${msg})`,
|
|
281
|
-
hint:
|
|
355
|
+
message: `查询内存不足(${stripOomSolutions(msg)})`,
|
|
356
|
+
hint: OOM_HINT,
|
|
282
357
|
};
|
|
283
358
|
}
|
|
284
359
|
// ⑧ 其余执行期错误 → internal,中文包装 + 底层原文(不裸透,spec §十一 末行)。
|
|
@@ -296,12 +371,14 @@ export function classifyDuckDbError(e, tables) {
|
|
|
296
371
|
* spec §十一 分派表的 code 列(`query_error` / `sandbox_blocked`)——而命令层测试
|
|
297
372
|
* (plan Task 8「多语句 / COPY / ATTACH → sandbox_blocked」)正是按 code 断言的。
|
|
298
373
|
* ⚠️ **这是有意偏离 `usageFail`,不是遗漏**(controller 裁决 R9 concern #2 确认保留):
|
|
299
|
-
* 故这里复刻 usageFail 的 stderr 写法,stdout
|
|
300
|
-
*
|
|
301
|
-
* `
|
|
374
|
+
* 故这里复刻 usageFail 的 stderr 写法,stdout 交回 `output.ts` 的出口渲染,保留真实 code。
|
|
375
|
+
* ⚠️ 紧凑信封**必须复用 `failCompact`**(2026-11-02 实测修):此前这里只复刻了 stderr
|
|
376
|
+
* 写法、直接调 `fail()`,于是 `query --sql 'SELEC 1' --pretty` 输出**缩进**错误信封、
|
|
377
|
+
* 退出码 2 —— 与 `usageFail` 承诺的「用法错误永远紧凑」相反。复刻一半比不复刻更危险:
|
|
378
|
+
* 两处看着都在「照同一份契约做」,行为却不同。
|
|
302
379
|
*/
|
|
303
|
-
export function thrownToQueryExit(e, tables, noMask = false) {
|
|
304
|
-
return emitQueryFailure(classifyDuckDbError(e, tables), noMask);
|
|
380
|
+
export function thrownToQueryExit(e, tables, noMask = false, loc) {
|
|
381
|
+
return emitQueryFailure(classifyDuckDbError(e, tables, loc), noMask);
|
|
305
382
|
}
|
|
306
383
|
/**
|
|
307
384
|
* 已分类失败的唯一出口(`thrownToQueryExit` 与 `--table` 漂移识别共用)。
|
|
@@ -351,10 +428,11 @@ export function emitQueryFailure(f, noMask = false) {
|
|
|
351
428
|
};
|
|
352
429
|
const message = clean(f.message);
|
|
353
430
|
const hint = f.hint === undefined ? undefined : clean(f.hint);
|
|
431
|
+
const render = f.kind === 'usage' ? failCompact : fail;
|
|
354
432
|
if (f.kind === 'usage') {
|
|
355
433
|
process.stderr.write(message.endsWith('\n') ? message : message + '\n');
|
|
356
434
|
}
|
|
357
|
-
return
|
|
435
|
+
return render({
|
|
358
436
|
code: f.code, kind: f.kind, retryable: f.retryable,
|
|
359
437
|
message: message.replace(/\n+$/, ''),
|
|
360
438
|
...(hint !== undefined ? { hint } : {}),
|
|
@@ -371,24 +449,46 @@ export function emitQueryFailure(f, noMask = false) {
|
|
|
371
449
|
* 判据收紧到「缺失名确实属于该表的声明」才认作漂移 —— 否则可能把真实的代码 bug
|
|
372
450
|
*(生成的 SQL 里写错了列名)掩盖成环境问题。不属于时返回 null,交回原生分派。
|
|
373
451
|
*/
|
|
374
|
-
export function driftFailureFor(table, e) {
|
|
375
|
-
|
|
376
|
-
|
|
452
|
+
export function driftFailureFor(table, e, loc) {
|
|
453
|
+
// ⚠️ 判据要吃**原生原文**:sandbox 把 prepare 期的原生错误包成 `SQL 无法执行:…` 并把原文
|
|
454
|
+
// 挂在 `cause` 上(裁决 R9),而 2026-11-01 起表/列判据要求「DuckDB 自己那句话在报文
|
|
455
|
+
// 开头」—— 拿包装后的中文串去判会**永远不命中**(本用例实测:删列后 hint 退化成
|
|
456
|
+
// 「用 db describe <表> 查看列清单」,把用户支使去改一个它没写过的东西,正是本函数要防的)。
|
|
457
|
+
const msg = errorText(e?.cause ?? e);
|
|
458
|
+
const byTable = matchMissingName(msg, [TABLE_NAME_RE, TABLE_REF_RE]);
|
|
377
459
|
if (byTable !== null && byTable[1] === table.name) {
|
|
378
460
|
return {
|
|
379
461
|
code: 'query_error', kind: 'usage', retryable: false,
|
|
380
462
|
message: `表 ${table.name} 在库中不存在——与 TABLES 声明漂移(表被删或建库不完整)`,
|
|
381
|
-
hint:
|
|
382
|
-
+ '并考虑重新同步或重建库(`
|
|
463
|
+
hint: '这不是你的查询写错了:本命令的 SQL 由 CLI 生成。用 `' + dbDescribeCommand(table.name, loc) + '` 核对,'
|
|
464
|
+
+ '并考虑重新同步或重建库(`'
|
|
465
|
+
+ (loc?.db !== undefined ? storeInitCommand(loc.db) : 'qiyu store init')
|
|
466
|
+
+ '` 只补未执行的迁移,不重建已删的表)',
|
|
383
467
|
};
|
|
384
468
|
}
|
|
385
|
-
const byColumn =
|
|
469
|
+
const byColumn = matchMissingName(msg, [COLUMN_NAMED_RE, COLUMN_NAME_RE]);
|
|
386
470
|
if (byColumn !== null && table.columns.some((c) => c.name === byColumn[1])) {
|
|
471
|
+
const missing = byColumn[1];
|
|
472
|
+
// 被删的恰好是**时间列**时,hint 只指 db describe 等于没有出路(2026-11-09 审计实测):
|
|
473
|
+
// 本命令的 WHERE/SELECT 由代码按声明生成,只要时间列不在库里,任何 --since/--until
|
|
474
|
+
// 查询都会以同一条错误失败,--group-by 也绕不过 SELECT 列表里的该列。所以必须说明
|
|
475
|
+
// 「修好之前哪些用法不可用」,并给出真能跑的替代(--sql 不行——它同样在 SELECT * 时撞列,
|
|
476
|
+
// 但可以显式列只取保留下来的列)。
|
|
477
|
+
const timeCol = table.timeColumn;
|
|
478
|
+
const isTimeCol = timeCol !== undefined && timeCol.name === missing;
|
|
479
|
+
const hint = isTimeCol
|
|
480
|
+
? '这不是你的查询写错了:本命令的 SQL 由 CLI 生成,列名来自 TABLES 声明。'
|
|
481
|
+
+ `时间列 ${missing} 恢复前,本命令对该表的 --since/--until(以及默认的整表查询)都会失败;`
|
|
482
|
+
+ '用 `' + querySqlCommand(loc) + '` 显式列出其余列(不选 ' + missing + ')可先把已有数据读出来('
|
|
483
|
+
+ SQL_ARG_REPLACE_NOTE + '),'
|
|
484
|
+
+ '根因修复用 `' + dbDescribeCommand(table.name, loc) + '` 核对漂移后重新同步或重建库'
|
|
485
|
+
: '这不是你的查询写错了:本命令的 SQL 由 CLI 生成,列名来自 TABLES 声明。'
|
|
486
|
+
+ '用 `' + dbDescribeCommand(table.name, loc) + '` 查看实际列集与漂移警告,'
|
|
487
|
+
+ '并按提示重新同步或重建库';
|
|
387
488
|
return {
|
|
388
489
|
code: 'query_error', kind: 'usage', retryable: false,
|
|
389
|
-
message: `列 ${
|
|
390
|
-
hint
|
|
391
|
-
+ `用 \`qiyu db describe ${table.name}\` 查看实际列集与漂移警告`,
|
|
490
|
+
message: `列 ${missing} 在库中不存在(表 ${table.name})——库与 TABLES 声明漂移`,
|
|
491
|
+
hint,
|
|
392
492
|
};
|
|
393
493
|
}
|
|
394
494
|
return null;
|