From 9432b65a20add839e607ae457268a96fd52cc4f6 Mon Sep 17 00:00:00 2001 From: ssw Date: Sat, 27 Jun 2026 03:50:19 +0800 Subject: [PATCH] feat(msg-templatecreate): v0.11e+ step machine + enhanceFromBackend (Phase D1) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit msg/templatecreate.ts: - import validateMsgCreate + enhanceFromBackend/formatErrorLine - 跑 step machine (fullName/enCode 必填 + MSERR114 系统编码规则禁止 sys_/system_ 开头) - catch 后端错时 enhanceFromBackend --- src/commands/msg/templatecreate.ts | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/commands/msg/templatecreate.ts b/src/commands/msg/templatecreate.ts index 470900a..c4a7d27 100644 --- a/src/commands/msg/templatecreate.ts +++ b/src/commands/msg/templatecreate.ts @@ -1,5 +1,5 @@ /** - * commands/msg/templatecreate.ts — 新建消息模板 + * commands/msg/templatecreate.ts — 新建消息模板 (v0.11e+ Phase D1 wire up) * * 走 JNPF MessageTemplateConfig 端点 (web 真实端点, v0.11+ P0 修复) * @@ -11,6 +11,8 @@ import { Command } from 'commander' import { JnpfClient } from '../../core/client.ts' import { installAiHelpHook } from '../../core/help.ts' import { log, printJson } from '../../core/log.ts' +import { validateMsgCreate } from './_validate.ts' +import { enhanceFromBackend, formatErrorLine } from '../_error_codes.ts' interface CreateOpts { fullName: string @@ -31,6 +33,22 @@ export function buildMsgTemplateCreateCommand(): Command { .option('--json', '原始 JSON 输出', false) .action(async (opts: CreateOpts) => { const c = await JnpfClient.fromToken() + + // v0.11e+ Phase D1: step machine 校验 (fullName/enCode 必填 + MSERR114 系统编码规则) + const validation = validateMsgCreate({ + fullName: opts.fullName, + enCode: opts.enCode, + }) + if (!validation.ok) { + for (const s of validation.steps) { + for (const e of s.errors) { + log.error(` ${formatErrorLine(e, { step: s.step, stepName: s.stepName })}`) + } + } + process.exit(1) + } + log.info(`✓ step machine 校验通过 (${validation.steps.length}/${validation.steps.length})`) + const body = { fullName: opts.fullName, enCode: opts.enCode, @@ -42,7 +60,8 @@ export function buildMsgTemplateCreateCommand(): Command { // web 端真实端点: /api/message/MessageTemplateConfig const r = await c.postJson<{ id?: string }>('/message/MessageTemplateConfig', body) if (r.code !== 200) { - log.error(`msg templatecreate 失败 (code=${r.code}): ${r.msg}`) + const enhanced = enhanceFromBackend(r.msg || '', 'msgTemplate', { entity: 'msg' }) + log.error(` ${formatErrorLine(enhanced, { step: 1, stepName: '后端API' })}`) process.exit(1) } let id = r.data?.id