flipped-aurora/gin-vue-admin · error

cli名称不能为空

Error message

cli名称不能为空

What it means

CreateCli in the ai plugin creates a SysCli record. It trims req.Name and rejects an empty result with this error before any uniqueness check, because a CLI without a name cannot be identified or invoked. The empty-name guard is the first validation in the create flow.

Source

Thrown at server/plugin/ai/service/sys_cli.go:21

import (
	"context"
	"errors"
	"strings"

	"github.com/flipped-aurora/gin-vue-admin/server/global"
	sysModel "github.com/flipped-aurora/gin-vue-admin/server/model/system"
	autoModel "github.com/flipped-aurora/gin-vue-admin/server/plugin/ai/model"
	autoReq "github.com/flipped-aurora/gin-vue-admin/server/plugin/ai/model/request"
	autoRes "github.com/flipped-aurora/gin-vue-admin/server/plugin/ai/model/response"
	"gorm.io/gorm"
)

type cliService struct{}

func (s *cliService) CreateCli(ctx context.Context, req autoReq.CreateSysCliRequest) (autoModel.SysCli, error) {
	name := strings.TrimSpace(req.Name)
	if name == "" {
		return autoModel.SysCli{}, errors.New("cli名称不能为空")
	}
	if exists, err := s.sysCliNameExists(ctx, name, 0); err != nil {
		return autoModel.SysCli{}, err
	} else if exists {
		return autoModel.SysCli{}, errors.New("存在同名CLI")
	}
	entity := autoModel.SysCli{
		Name:             name,
		Command:          strings.TrimSpace(req.Command),
		DisplayName:      strings.TrimSpace(req.DisplayName),
		Version:          strings.TrimSpace(req.Version),
		Description:      strings.TrimSpace(req.Description),
		Status:           strings.TrimSpace(req.Status),
		AuthMode:         "jwt",
		SkillName:        strings.TrimSpace(req.SkillName),
		SkillDescription: strings.TrimSpace(req.SkillDescription),
		ScenariosJSON:    req.ScenariosJSON, // JSON 原文不裁剪
	}

View on GitHub (pinned to 3136500ef3)

Solutions

  1. Provide a non-empty name in the request body: {"name":"my-cli", ...}
  2. Make the name field required in the frontend form and validate before submit
  3. Trim input on the client too so whitespace-only values are caught early
  4. If calling programmatically, assert name is present before invoking the API

Example fix

// before
await createCli({ command: 'run', displayName: 'My CLI' })
// after
await createCli({ name: 'my-cli', command: 'run', displayName: 'My CLI' })
Defensive patterns

Strategy: validation

Validate before calling

// client-side
const name = String(req.name ?? '').trim()
if (!name) throw new Error('name is required to create a CLI')

Type guard

function hasCliName(r) {
  return typeof r?.name === 'string' && r.name.trim().length > 0
}

Try / catch

try {
  await createCli(req)
} catch (e) {
  if (String(e.message).includes('cli名称不能为空')) {
    formRef.value.validateField('name')
  } else { throw e }
}

Prevention

When it happens

Trigger: Calling CreateCli (via the ai plugin API or MCP tool) with CreateSysCliRequest.Name empty or whitespace-only — e.g. a form field left blank, or programmatic callers omitting name.

Common situations: Frontend CLI management form submitted without the name input; scripts/API consumers building the request without `name`; whitespace-only input from copy-paste that passes naive required checks.

Understand the failure class

Background: "Missing required field" and "field is required" errors: why libraries reject payloads that omit mandatory fields — this error's family across 20 libraries.

Related errors


AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31). Data as JSON: /api/errors/e081ef346981b09b. Report an issue: GitHub.