bytebase/bytebase · error

failed to find workspace

Error message

failed to find workspace

What it means

This error wraps a failure from store.GetWorkspaceByID: the workspace lookup query itself errored (as opposed to the workspace not existing). Callers like ResetUserPassword, AddUserToWorkspace, and ListRoles require a valid workspace before proceeding.

Source

Thrown at backend/component/recovery/service.go:412

		return nil, errors.Errorf("user %q does not exist", email)
	}
	if account.Type != storepb.PrincipalType_END_USER || account.MemberDeleted {
		return nil, errors.Errorf("user %q is not an active end user", email)
	}
	user, err := s.store.GetUserByEmail(ctx, email)
	if err != nil {
		return nil, errors.Wrap(err, "failed to load user identity")
	}
	if user == nil || user.MemberDeleted {
		return nil, errors.Errorf("user %q is not an active end user", email)
	}
	return user, nil
}

func (s *Service) requireWorkspace(ctx context.Context, workspaceID string) error {
	workspace, err := s.store.GetWorkspaceByID(ctx, workspaceID)
	if err != nil {
		return errors.Wrap(err, "failed to find workspace")
	}
	if workspace == nil {
		return errors.Errorf("workspace %q was not found", workspaceID)
	}
	return nil
}

func emailBelongsToDomains(email string, domains []string) bool {
	if len(domains) == 0 {
		return true
	}
	for _, domain := range domains {
		if strings.HasSuffix(email, "@"+strings.ToLower(domain)) {
			return true
		}
	}
	return false
}

View on GitHub (pinned to 1870550677)

Solutions

  1. Check the wrapped cause for the database error; verify metadata DB connectivity and configuration.
  2. Retry if the error is transient (timeout, connection reset).
  3. Validate the workspace ID format before calling the API so it fails as not-found rather than as a query error.
  4. Confirm workspace table migrations have been applied.

Example fix

// before
workspace, err := s.store.GetWorkspaceByID(ctx, workspaceID)
if err != nil {
	return errors.Wrap(err, "failed to find workspace")
}
// after
if workspaceID == "" {
	return errors.New("workspace id is required")
}
workspace, err := s.store.GetWorkspaceByID(ctx, workspaceID)
if err != nil {
	return errors.Wrapf(err, "failed to find workspace %s (check metadata DB)", workspaceID)
}
Defensive patterns

Strategy: validation

Validate before calling

if workspaceID == "" {
	return errors.New("workspace id is required")
}
if err := db.PingContext(ctx); err != nil {
	return fmt.Errorf("metadata DB unreachable: %w", err)
}

Try / catch

err := svc.requireWorkspace(ctx, workspaceID)
if err != nil && strings.Contains(err.Error(), "failed to find workspace") {
	// DB-level failure: retry transient errors
	return retryWithBackoff(3, time.Second, func() error { return svc.requireWorkspace(ctx, workspaceID) })
}

Prevention

When it happens

Trigger: requireWorkspace calls s.store.GetWorkspaceByID(ctx, workspaceID) and it returns err != nil — metadata database failure, timeout, or SQL error — from any of EnablePasswordSignin, GetPasswordRestriction, IsUserInWorkspace, ListRoles, AddUserToWorkspace, or ResetUserPassword.

Common situations: Metadata database outage or wrong PG_URL; connection pool exhaustion under load; passing an unparseable workspace ID that causes a query error rather than a clean not-found.

Understand the failure class

Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.

Related errors


AI-assisted analysis of bytebase/bytebase@1870550677 (2026-09-06). Data as JSON: /api/errors/91a9ca61d6c13bff. Report an issue: GitHub.