{"record":{"id":"6fd9d2727448469c","repo":"bytebase/bytebase","slug":"failed-to-marshal-recovery-audit-request","errorCode":null,"errorMessage":"failed to marshal recovery audit request","messagePattern":"failed to marshal recovery audit request","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"backend/component/recovery/service.go","lineNumber":131,"sourceCode":"\t\t}\n\t\tadmin, err := s.store.GetUserByEmail(ctx, effectiveAdmin.Email)\n\t\tif err != nil {\n\t\t\treturn nil, errors.Wrapf(err, \"failed to load effective administrator %q\", effectiveAdmin.Email)\n\t\t}\n\t\tif admin != nil && !admin.MemberDeleted && admin.PasswordHash != \"\" {\n\t\t\tusableAdminCount++\n\t\t}\n\t}\n\tif usableAdminCount == 0 {\n\t\treturn nil, errors.New(\"no usable workspace administrator has an active end-user identity with a password credential\")\n\t}\n\tauditRequest, err := json.Marshal(struct {\n\t\tWorkspace string `json:\"workspace\"`\n\t}{\n\t\tWorkspace: common.FormatWorkspace(workspaceID),\n\t})\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"failed to marshal recovery audit request\")\n\t}\n\n\tif _, err := s.store.UpdateSettingAtomic(\n\t\tctx,\n\t\tworkspaceID,\n\t\tstorepb.SettingName_WORKSPACE_PROFILE,\n\t\tfunc(current proto.Message) (proto.Message, error) {\n\t\t\tprofile, ok := current.(*storepb.WorkspaceProfileSetting)\n\t\t\tif !ok {\n\t\t\t\treturn nil, errors.New(\"workspace profile setting has an unexpected type\")\n\t\t\t}\n\t\t\tprofile.DisallowPasswordSignin = false\n\t\t\treturn profile, nil\n\t\t},\n\t\tnil,\n\t); err != nil {\n\t\treturn nil, errors.Wrap(err, \"failed to enable password sign-in\")\n\t}","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/bytebase/bytebase/blob/1870550677fe08f0d2a78c07acd27541464eb945/backend/component/recovery/service.go#L113-L149","documentation":"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.","triggerScenarios":"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.","commonSituations":"Essentially theoretical; would appear only if the struct or FormatWorkspace output were changed to include unsupported types (channels, funcs, cycles) in a code modification.","solutions":["Inspect the wrapped error; verify the workspaceID passed to EnablePasswordSignin is a plain string resource ID","If you modified the audit struct, ensure all fields are JSON-serializable types","Retry — transient runtime conditions are the only realistic cause"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if _, err := json.Marshal(map[string]string{\"workspace\": common.FormatWorkspace(workspaceID)}); err != nil {\n    return fmt.Errorf(\"audit payload not serializable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"result, err := svc.EnablePasswordSignin(ctx, wsID)\nif err != nil && strings.Contains(err.Error(), \"failed to marshal recovery audit request\") {\n    return fmt.Errorf(\"audit payload construction failed: %w\", err)\n}","preventionTips":["Keep audit payload structs limited to JSON-native types","Never add channels/funcs/cycles to audit structs"],"tags":["recovery","audit","json"],"backgroundTag":"json-marshal-failed","analyzedSha":"1870550677fe08f0d2a78c07acd27541464eb945","analyzedAt":"2026-09-06T21:16:13.665Z","contentChangedAt":"2026-09-06T21:16:13.665Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}