chenhg5/cc-connect · error

ensure project: %w

Error message

ensure project: %w

What it means

During an interactive registration/setup request handling, an EnsureProject-style call (creating a project record with name, platform type, workdir, agent type) failed, and the error is wrapped as "ensure project: %w". This is a propagated upstream error — the root cause is inside the wrapped error, not the wrapper itself.

Source

Thrown at cmd/cc-connect/main.go:1126

			mgmtSrv.SetTimerScheduler(timerSched)
		}
		mgmtSrv.SetHeartbeatScheduler(heartbeatSched)
		if bridgeSrv != nil {
			mgmtSrv.SetBridgeServer(bridgeSrv)
		}
		mgmtSrv.SetSetupFeishuSave(func(req core.FeishuSetupSaveRequest) error {
			platType := req.PlatformType
			if platType == "" {
				platType = "feishu"
			}
			_, err := config.EnsureProjectWithFeishuPlatform(config.EnsureProjectWithFeishuOptions{
				ProjectName:  req.ProjectName,
				PlatformType: platType,
				WorkDir:      req.WorkDir,
				AgentType:    req.AgentType,
			})
			if err != nil {
				return fmt.Errorf("ensure project: %w", err)
			}
			_, err = config.SaveFeishuPlatformCredentials(config.FeishuCredentialUpdateOptions{
				ProjectName:       req.ProjectName,
				PlatformType:      platType,
				AppID:             req.AppID,
				AppSecret:         req.AppSecret,
				OwnerOpenID:       req.OwnerOpenID,
				SetAllowFromEmpty: true,
			})
			return err
		})
		mgmtSrv.SetSetupWeixinSave(func(req core.WeixinSetupSaveRequest) error {
			_, err := config.EnsureProjectWithWeixinPlatform(config.EnsureProjectWithWeixinOptions{
				ProjectName: req.ProjectName,
				WorkDir:     req.WorkDir,
				AgentType:   req.AgentType,
			})
			if err != nil {

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Read the wrapped root cause after "ensure project:" in the error chain — fix that first.
  2. Verify req.WorkDir exists and is a directory before invoking the flow.
  3. Check whether a project with req.ProjectName already exists and use a unique name.
  4. Validate AgentType/PlatformType values against registered agents/platforms.

Example fix

// before
EnsureProject(...ProjectName: req.ProjectName, WorkDir: req.WorkDir...)
// after
if st, err := os.Stat(req.WorkDir); err != nil || !st.IsDir() {
    return fmt.Errorf("workdir does not exist: %s", req.WorkDir)
}
EnsureProject(...)
Defensive patterns

Strategy: validation

Validate before calling

if st, err := os.Stat(req.WorkDir); err != nil || !st.IsDir() {
    return fmt.Errorf("workdir invalid: %s", req.WorkDir)
}
if req.ProjectName == "" || req.AgentType == "" {
    return fmt.Errorf("project name and agent type are required")
}

Try / catch

if err := EnsureProject(EnsureProjectOptions{...}); err != nil {
    return fmt.Errorf("ensure project: %w", err) // inspect chained cause with errors.Unwrap
}

Prevention

When it happens

Trigger: The registration flow in main.go calls the project-ensuring API with req.ProjectName/PlatformType/WorkDir/AgentType and receives an error (e.g. invalid workdir, duplicate project, underlying persistence failure).

Common situations: WorkDir does not exist or is not absolute; a project with the same name already exists; the underlying config/persistence layer failed; invalid agent type string in the request.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/1606863d86d5548a. Report an issue: GitHub.