bytebase/bytebase · warning

failed to marshal recovery audit request

Error message

failed to marshal recovery audit request

What it means

EnablePasswordSignin builds a small JSON audit payload ({"workspace": "workspaces/..."}) before writing the audit log. If json.Marshal fails, the operation is aborted before any settings change with this wrapped error. In practice this is nearly unreachable since the payload is a fixed single-field struct with a plain string.

Source

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

		}
		admin, err := s.store.GetUserByEmail(ctx, effectiveAdmin.Email)
		if err != nil {
			return nil, errors.Wrapf(err, "failed to load effective administrator %q", effectiveAdmin.Email)
		}
		if admin != nil && !admin.MemberDeleted && admin.PasswordHash != "" {
			usableAdminCount++
		}
	}
	if usableAdminCount == 0 {
		return nil, errors.New("no usable workspace administrator has an active end-user identity with a password credential")
	}
	auditRequest, err := json.Marshal(struct {
		Workspace string `json:"workspace"`
	}{
		Workspace: common.FormatWorkspace(workspaceID),
	})
	if err != nil {
		return nil, errors.Wrap(err, "failed to marshal recovery audit request")
	}

	if _, err := s.store.UpdateSettingAtomic(
		ctx,
		workspaceID,
		storepb.SettingName_WORKSPACE_PROFILE,
		func(current proto.Message) (proto.Message, error) {
			profile, ok := current.(*storepb.WorkspaceProfileSetting)
			if !ok {
				return nil, errors.New("workspace profile setting has an unexpected type")
			}
			profile.DisallowPasswordSignin = false
			return profile, nil
		},
		nil,
	); err != nil {
		return nil, errors.Wrap(err, "failed to enable password sign-in")
	}

View on GitHub (pinned to 1870550677)

Solutions

  1. Inspect the wrapped error; verify the workspaceID passed to EnablePasswordSignin is a plain string resource ID
  2. If you modified the audit struct, ensure all fields are JSON-serializable types
  3. Retry — transient runtime conditions are the only realistic cause
Defensive patterns

Strategy: try-catch

Validate before calling

if _, err := json.Marshal(map[string]string{"workspace": common.FormatWorkspace(workspaceID)}); err != nil {
    return fmt.Errorf("audit payload not serializable: %w", err)
}

Try / catch

result, err := svc.EnablePasswordSignin(ctx, wsID)
if err != nil && strings.Contains(err.Error(), "failed to marshal recovery audit request") {
    return fmt.Errorf("audit payload construction failed: %w", err)
}

Prevention

When it happens

Trigger: Calling EnablePasswordSignin where json.Marshal of the audit struct fails — realistically only if common.FormatWorkspace(workspaceID) somehow yields data that cannot be marshaled, or an out-of-memory/rare encoding/json internal failure.

Common situations: Essentially theoretical; would appear only if the struct or FormatWorkspace output were changed to include unsupported types (channels, funcs, cycles) in a code modification.

Understand the failure class

Background: json.Marshal / "failed to marshal" errors in Go: why "unsupported type" happens and how to fix it — this error's family across 22 libraries.

Related errors


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