flipped-aurora/gin-vue-admin · error

读取service文件夹失败!

Error message

读取service文件夹失败!

What it means

The All method scans the filesystem under AutoCode.Root/Server to discover packages as directories, treating 'service' and 'plugin' as package sources. This error wraps a failure of os.ReadDir on the service directory, meaning the path could not be read (missing or permission).

Source

Thrown at server/service/system/auto_code_package.go:142

	}
	err := global.GVA_DB.WithContext(ctx).Where("package_name IN ?", names).Delete(&model.SysAutoCodePackage{}).Error
	if err != nil {
		return errors.Wrap(err, "删除失败!")
	}
	return nil
}

// All 获取所有包
// @author: [piexlmax](https://github.com/piexlmax)
// @author: [SliverHorn](https://github.com/SliverHorn)
func (s *autoCodePackage) All(ctx context.Context) (entities []model.SysAutoCodePackage, err error) {
	server := make([]model.SysAutoCodePackage, 0)
	plugin := make([]model.SysAutoCodePackage, 0)
	serverPath := filepath.Join(global.GVA_CONFIG.AutoCode.Root, global.GVA_CONFIG.AutoCode.Server, "service")
	pluginPath := filepath.Join(global.GVA_CONFIG.AutoCode.Root, global.GVA_CONFIG.AutoCode.Server, "plugin")
	serverDir, err := os.ReadDir(serverPath)
	if err != nil {
		return nil, errors.Wrap(err, "读取service文件夹失败!")
	}
	pluginDir, err := os.ReadDir(pluginPath)
	if err != nil {
		return nil, errors.Wrap(err, "读取plugin文件夹失败!")
	}
	for i := 0; i < len(serverDir); i++ {
		if serverDir[i].IsDir() {
			serverPackage := model.SysAutoCodePackage{
				PackageName: serverDir[i].Name(),
				Template:    "package",
				Label:       serverDir[i].Name() + "包",
				Desc:        "系统自动读取" + serverDir[i].Name() + "包",
				Module:      global.GVA_CONFIG.AutoCode.Module,
			}
			server = append(server, serverPackage)
		}
	}
	for i := 0; i < len(pluginDir); i++ {

View on GitHub (pinned to 3136500ef3)

Solutions

  1. Verify config.yaml auto-code root/server values match the actual server source location
  2. Create the missing service directory or fix the path so <root>/<server>/service exists
  3. Ensure the process user has read permission on that directory
  4. Run the server from the expected working directory if Root is relative

Example fix

# before (config.yaml)
auto-code:
  root: ./old-path
# after
auto-code:
  root: /path/to/project
Defensive patterns

Strategy: validation

Validate before calling

serverPath := filepath.Join(global.GVA_CONFIG.AutoCode.Root, global.GVA_CONFIG.AutoCode.Server, "service")
if info, err := os.Stat(serverPath); err != nil {
    return fmt.Errorf("service dir missing: %s", serverPath)
} else if !info.IsDir() {
    return fmt.Errorf("%s is not a directory", serverPath)
}
if file, err := os.Open(serverPath); err != nil {
    return fmt.Errorf("service dir unreadable: %w", err)
} else {
    file.Close()
}

Try / catch

serverDir, err := os.ReadDir(serverPath)
if err != nil {
    if os.IsNotExist(err) {
        return nil, fmt.Errorf("service dir %s not found; check auto-code config", serverPath)
    }
    return nil, errors.Wrap(err, "读取service文件夹失败!")
}

Prevention

When it happens

Trigger: Calling autoCodePackage.All when filepath.Join(AutoCode.Root, AutoCode.Server, "service") does not exist or is unreadable — typically misconfigured AutoCode.Root/AutoCode.Server in config, or the project layout was moved.

Common situations: Running the backend from a different working directory so relative Root config resolves wrong; AutoCode.Server left at default while repo is checked out elsewhere; renamed/moved service directory in a customized repo.

Related errors


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