flipped-aurora/gin-vue-admin · error

自动代码目标不在服务端或前端目录内: %s

Error message

自动代码目标不在服务端或前端目录内: %s

What it means

The auto-code task layout classifier (classify) resolves a target file path to either the backend (serverRoot) or frontend (webRoot) root by checking path containment. If the resolved target is inside neither root, it returns this error and no publish/rollback task can be prepared. It is a safety guard so generated files are only managed within the known server/web trees.

Source

Thrown at server/service/system/auto_code_task.go:298

		return fmt.Errorf("写入临时文件失败: %w", err)
	}
	if err = os.Chmod(tmpName, mode.Perm()); err != nil {
		return fmt.Errorf("设置临时文件权限失败: %w", err)
	}
	if err = os.Rename(tmpName, target); err != nil {
		return fmt.Errorf("原子替换 %s 失败: %w", target, err)
	}
	return nil
}

func (l autoCodeTaskLayout) classify(target string) (string, error) {
	if isPathWithin(l.serverRoot, target) {
		return autoCodeTaskBackend, nil
	}
	if isPathWithin(l.webRoot, target) {
		return autoCodeTaskFrontend, nil
	}
	return "", fmt.Errorf("自动代码目标不在服务端或前端目录内: %s", target)
}

func pathWithin(root string, elems ...string) (string, error) {
	root, err := filepath.Abs(root)
	if err != nil {
		return "", err
	}
	joined := filepath.Join(append([]string{root}, elems...)...)
	joined, err = filepath.Abs(joined)
	if err != nil {
		return "", err
	}
	if !isPathWithin(root, joined) {
		return "", fmt.Errorf("路径越过根目录: %s", joined)
	}
	return filepath.Clean(joined), nil
}

View on GitHub (pinned to 3136500ef3)

Solutions

  1. Check server/config.yaml autoCode section: root/server/web must point at the actual server/ and web/ directories of this project.
  2. Verify the offending target path printed in the message and trace which template/config produced it; correct it to a path inside server/ or web/.
  3. If symlinks are involved, ensure the real (absolute) resolved path still falls under serverRoot or webRoot.
  4. Restart the server after config changes so the autoCodeTaskLayout is rebuilt with correct roots.

Example fix

// before (config.yaml)
autoCode:
  root: '/opt/other-project'
// after
autoCode:
  root: '/path/to/gin-vue-admin'
  server: 'server'
  web: 'web'
Defensive patterns

Strategy: validation

Validate before calling

root, _ := filepath.Abs("server")
target, _ := filepath.Abs(targetPath)
rel, err := filepath.Rel(root, target)
if err != nil || strings.HasPrefix(rel, "..") {
    return fmt.Errorf("target %s is outside server/", targetPath)
}

Try / catch

if err := prepareAutoCodeFileTask(...); err != nil {
    if strings.Contains(err.Error(), "不在服务端或前端目录内") {
        // fix autoCode config / target path and retry
    }
    return err
}

Prevention

When it happens

Trigger: Calling prepareAutoCodeFileTask (or the anonymous publish/rollback wrapper) with a target path configured outside both GVA_CONFIG.AutoCode server and web roots, e.g. a misconfigured AutoCode.Root or a custom template writing to an absolute path like /tmp or another project directory.

Common situations: config.yaml AutoCode.Root/Server/Web values pointing to relocated directories; moving the repo after generating tasks; users setting custom output dirs in the code generator UI that escape the project; symlinked paths that resolve outside the roots after filepath.Abs.

Related errors


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