diff --git a/src/commands/datasource/test.ts b/src/commands/datasource/test.ts index 19089cd..2b4f0b6 100644 --- a/src/commands/datasource/test.ts +++ b/src/commands/datasource/test.ts @@ -11,6 +11,7 @@ import { log, printJson } from '../../core/log.ts' import { encryptAesEcb, isEncrypted } from '../../core/crypto.ts' import { initWebapi, loadDataSource } from '../../webapi/dataSource.ts' import { enhanceFromBackend, formatErrorLine } from '../_error_codes.ts' +import { DacliError } from '../../core/types.ts' import { setupOutputFilter, addOutputOptions, wrapCommand } from '../_output_filter.ts' // v2.1+ (2026-07-21): 输出过滤 + CommandLog 落盘; v2.2+ wrapCommand helper 收口 5c 样板 interface TestOpts { @@ -68,12 +69,12 @@ export function buildDatasourceTestCommand(): Command { oracleExtend: opts.dbType === 'Oracle' ? 1 : 0, } } else { - throw new Error('请传 --id <数据源 id> 或 --dbType + --host + --user + --password') + throw new DacliError('请传 --id <数据源 id> 或 --dbType + --host + --user + --password') } const r = (await loadDataSource.testDbConnection(body)) as { code?: number; msg?: string; data?: unknown } if (r.code !== undefined && r.code !== 200) { const enhanced = enhanceFromBackend(r.msg || '', 'datasource', { entity: 'datasource' }) - throw new Error(formatErrorLine(enhanced, { step: 0, stepName: '后端API' })) + throw new DacliError(formatErrorLine(enhanced, { step: 0, stepName: '后端API' })) } log.info(`✓ 数据源连接成功`) const summary = { id: opts.id, dbType: opts.dbType || body.dbType as string, ok: true } diff --git a/src/commands/integration/emailtest.ts b/src/commands/integration/emailtest.ts index 5296da0..bb6181d 100644 --- a/src/commands/integration/emailtest.ts +++ b/src/commands/integration/emailtest.ts @@ -14,6 +14,7 @@ import { log } from '../../core/log.ts' import { enhanceFromBackend, formatErrorLine } from '../_error_codes.ts' import { setupOutputFilter, addOutputOptions, printCommandEnd } from '../_output_filter.ts' // v2.1+ (2026-07-21): 输出过滤 + CommandLog 落盘 +import { DacliError } from '../../core/types.ts' interface EmailTestOpts { configId: string email?: string @@ -46,7 +47,7 @@ export function buildIntegrationEmailTestCommand(): Command { const configR = await c.get>(`/message/AccountConfig/${opts.configId}`) if (configR.code !== 200 || !configR.data) { const enhanced = enhanceFromBackend(configR.msg || 'id 不存在', 'configId', { entity: 'integration' }) - throw new Error(formatErrorLine(enhanced, { step: 0, stepName: '配置拉取' })) + throw new DacliError(formatErrorLine(enhanced, { step: 0, stepName: '配置拉取' })) } const config = configR.data @@ -63,7 +64,7 @@ export function buildIntegrationEmailTestCommand(): Command { const r = await c.postJson('/message/AccountConfig/testSendMail', body) if (r.code !== 200) { const enhanced = enhanceFromBackend(r.msg || '', 'email', { entity: 'integration' }) - throw new Error(formatErrorLine(enhanced, { step: 1, stepName: '后端API' })) + throw new DacliError(formatErrorLine(enhanced, { step: 1, stepName: '后端API' })) } log.info(`✓ 邮件测试发送 OK (configId=${opts.configId}, to=${opts.email})`) cmdSummary = { configId: opts.configId, email: opts.email, ok: true } diff --git a/src/commands/integration/smstest.ts b/src/commands/integration/smstest.ts index 3544ca2..cc73ebe 100644 --- a/src/commands/integration/smstest.ts +++ b/src/commands/integration/smstest.ts @@ -14,6 +14,7 @@ import { log } from '../../core/log.ts' import { enhanceFromBackend, formatErrorLine } from '../_error_codes.ts' import { setupOutputFilter, addOutputOptions, printCommandEnd } from '../_output_filter.ts' // v2.1+ (2026-07-21): 输出过滤 + CommandLog 落盘 +import { DacliError } from '../../core/types.ts' interface SmsTestOpts { configId: string phone?: string @@ -44,7 +45,7 @@ export function buildIntegrationSmsTestCommand(): Command { const configR = await c.get>(`/message/AccountConfig/${opts.configId}`) if (configR.code !== 200 || !configR.data) { const enhanced = enhanceFromBackend(configR.msg || 'id 不存在', 'configId', { entity: 'integration' }) - throw new Error(formatErrorLine(enhanced, { step: 0, stepName: '配置拉取' })) + throw new DacliError(formatErrorLine(enhanced, { step: 0, stepName: '配置拉取' })) } const config = configR.data @@ -62,7 +63,7 @@ export function buildIntegrationSmsTestCommand(): Command { const r = await c.postJson('/message/AccountConfig/testSendSms', body) if (r.code !== 200) { const enhanced = enhanceFromBackend(r.msg || '', 'sms', { entity: 'integration' }) - throw new Error(formatErrorLine(enhanced, { step: 1, stepName: '后端API' })) + throw new DacliError(formatErrorLine(enhanced, { step: 1, stepName: '后端API' })) } log.info(`✓ 短信测试发送 OK (configId=${opts.configId}, to=${opts.phone})`) cmdSummary = { configId: opts.configId, phone: opts.phone, ok: true } diff --git a/src/commands/integration/webhooktest.ts b/src/commands/integration/webhooktest.ts index 7502ee0..0cd59b2 100644 --- a/src/commands/integration/webhooktest.ts +++ b/src/commands/integration/webhooktest.ts @@ -14,6 +14,7 @@ import { log } from '../../core/log.ts' import { enhanceFromBackend, formatErrorLine } from '../_error_codes.ts' import { setupOutputFilter, addOutputOptions, printCommandEnd } from '../_output_filter.ts' // v2.1+ (2026-07-21): 输出过滤 + CommandLog 落盘 +import { DacliError } from '../../core/types.ts' interface WebhookTestOpts { configId?: string url?: string @@ -41,7 +42,7 @@ export function buildIntegrationWebhookTestCommand(): Command { try { if (!opts.configId && !opts.url) { - throw new Error('必须传 --configId 或 --url 之一') + throw new DacliError('必须传 --configId 或 --url 之一') } let body: Record @@ -51,7 +52,7 @@ export function buildIntegrationWebhookTestCommand(): Command { const configR = await c.get>(`/message/AccountConfig/${opts.configId}`) if (configR.code !== 200 || !configR.data) { const enhanced = enhanceFromBackend(configR.msg || 'id 不存在', 'configId', { entity: 'integration' }) - throw new Error(formatErrorLine(enhanced, { step: 0, stepName: '配置拉取' })) + throw new DacliError(formatErrorLine(enhanced, { step: 0, stepName: '配置拉取' })) } body = { ...configR.data, @@ -69,14 +70,14 @@ export function buildIntegrationWebhookTestCommand(): Command { try { body = { ...body, ...JSON.parse(opts.payload) } } catch (e) { - throw new Error(`--payload JSON 解析失败: ${(e as Error).message}`) + throw new DacliError(`--payload JSON 解析失败: ${(e as Error).message}`) } } const r = await c.postJson('/message/AccountConfig/testSendWebhook', body) if (r.code !== 200) { const enhanced = enhanceFromBackend(r.msg || '', 'webhook', { entity: 'integration' }) - throw new Error(formatErrorLine(enhanced, { step: 1, stepName: '后端API' })) + throw new DacliError(formatErrorLine(enhanced, { step: 1, stepName: '后端API' })) } log.info(`✓ Webhook 测试发送 OK (configId=${opts.configId || '-'}, url=${opts.url || '(from config)'})`) cmdSummary = { diff --git a/src/commands/report/info.ts b/src/commands/report/info.ts index 0cbb78a..5b03426 100644 --- a/src/commands/report/info.ts +++ b/src/commands/report/info.ts @@ -17,6 +17,7 @@ import { log, printJson } from '../../core/log.ts' import { initWebapi as initReportWebapi, loadReport } from '../../webapi/report.ts' import { setupOutputFilter, addOutputOptions, printCommandEnd } from '../_output_filter.ts' // v2.1+ (2026-07-21): 输出过滤 + CommandLog 落盘 (info 类查询历史可追溯) +import { DacliError } from '../../core/types.ts' interface ReportInfoItem { id?: string fullName?: string @@ -54,7 +55,7 @@ export function buildReportInfoCommand(): Command { const r = (await loadReport.getReportInfo(opts.id)) as ReportInfoItem | null const found = r if (!found || typeof found !== 'object' || !('id' in found)) { - throw new Error(`report id=${opts.id} 不存在 (webapi /api/Report/${opts.id} 返非 ReportInfoVO 或 null)`) + throw new DacliError(`report id=${opts.id} 不存在 (webapi /api/Report/${opts.id} 返非 ReportInfoVO 或 null)`) } cmdSummary = { id: opts.id, diff --git a/src/commands/report/list.ts b/src/commands/report/list.ts index 591f45d..61161df 100644 --- a/src/commands/report/list.ts +++ b/src/commands/report/list.ts @@ -23,6 +23,7 @@ import { log, printJson } from '../../core/log.ts' import { initWebapi as initReportWebapi, loadReport } from '../../webapi/report.ts' import { setupOutputFilter, addOutputOptions, printCommandEnd } from '../_output_filter.ts' // v2.1+ (2026-07-21): 输出过滤 + CommandLog 落盘 (list 类查询历史可追溯) +import { DacliError } from '../../core/types.ts' interface ReportListItem { id?: string fullName?: string @@ -88,7 +89,7 @@ export function buildReportListCommand(): Command { data?: { list?: ReportListItem[]; pagination?: { total?: number } } } if (r.code !== undefined && r.code !== 200) { - throw new Error(`report list 失败 (code=${r.code}): ${r.msg}`) + throw new DacliError(`report list 失败 (code=${r.code}): ${r.msg}`) } const list = r.data?.list || [] const total = r.data?.pagination?.total ?? list.length diff --git a/src/commands/storage/info.ts b/src/commands/storage/info.ts index 4b19fb2..7c65903 100644 --- a/src/commands/storage/info.ts +++ b/src/commands/storage/info.ts @@ -7,6 +7,7 @@ import { log, printJson } from '../../core/log.ts' import { installHelpHook } from '../../core/help.ts' import { setupOutputFilter, addOutputOptions, printCommandEnd } from '../_output_filter.ts' // v2.1+ (2026-07-21): 输出过滤 + CommandLog 落盘 (无 appCode, 跳过 L3 落盘, 仅 L1 summary) +import { DacliError } from '../../core/types.ts' interface InfoOpts { profile?: string yml?: string @@ -35,7 +36,7 @@ export function buildStorageInfoCommand(): Command { const found = cfg.platforms.find((p) => p.name === platform) if (!found) { const avail = cfg.platforms.map((p) => p.name).join(', ') || '(无)' - throw new Error(`platform '${platform}' 不在 yml 中, 可用: ${avail}`) + throw new DacliError(`platform '${platform}' 不在 yml 中, 可用: ${avail}`) } const masked = maskPlatform(found) cmdSummary = { diff --git a/src/commands/user/auth-list.ts b/src/commands/user/auth-list.ts index db210fc..1d6b915 100644 --- a/src/commands/user/auth-list.ts +++ b/src/commands/user/auth-list.ts @@ -11,6 +11,7 @@ import { JnpfClient } from '../../core/client.ts' import { installHelpHook } from '../../core/help.ts' import { log, printJson } from '../../core/log.ts' +import { DacliError } from '../../core/types.ts' interface AuthItem { id?: string fullName?: string @@ -42,7 +43,7 @@ export function buildUserAuthListCommand(): Command { .requiredOption('--objectId ', 'object id (从 auth-groups 拿)') .requiredOption('--objectType ', 'object 类型: role | position | organize', (v) => { if (!['role', 'position', 'organize'].includes(v)) { - throw new Error('objectType 必须是 role/position/organize') + throw new DacliError('objectType 必须是 role/position/organize') } return v }) diff --git a/src/commands/user/batch-state.ts b/src/commands/user/batch-state.ts index ebab61f..61a6f8b 100644 --- a/src/commands/user/batch-state.ts +++ b/src/commands/user/batch-state.ts @@ -10,6 +10,7 @@ import { JnpfClient } from '../../core/client.ts' import { installHelpHook } from '../../core/help.ts' import { log } from '../../core/log.ts' +import { DacliError } from '../../core/types.ts' interface BatchStateOpts { ids: string state: string @@ -21,7 +22,7 @@ export function buildUserBatchStateCommand(): Command { .requiredOption('--ids ', '用户 id 列表, 逗号分隔') .requiredOption('--state ', '状态: 0=禁用 1=启用 2=锁定', (v) => { const n = parseInt(v, 10) - if (![0, 1, 2].includes(n)) throw new Error('state 必须是 0/1/2') + if (![0, 1, 2].includes(n)) throw new DacliError('state 必须是 0/1/2') return v }) .action(async (opts: BatchStateOpts) => {