{"record":{"id":"7bc3f36d5e72188e","repo":"larksuite/cli","slug":"objective-s-w","errorCode":null,"errorMessage":"objective %s: %w","messagePattern":"objective (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/okr/okr_batch_create.go","lineNumber":170,"sourceCode":"\tif err != nil {\n\t\treturn wrapOkrNetworkErr(err, \"failed to delete objective %s during rollback\", objectiveID)\n\t}\n\treturn nil\n}\n\n// rollback deletes created objectives in reverse order.\n// KRs are automatically deleted by the backend when the objective is deleted.\nfunc rollback(ctx context.Context, runtime *common.RuntimeContext, created []createdObjective) []error {\n\tvar errsList []error\n\n\t// Iterate in reverse order\n\tfor i := len(created) - 1; i >= 0; i-- {\n\t\tobj := created[i]\n\n\t\t// Delete the objective (backend automatically deletes its KRs)\n\t\tif err := deleteObjective(ctx, runtime, obj.ObjectiveID); err != nil {\n\t\t\t//nolint:forbidigo // intermediate wrap for rollback error collection; final error is typed via buildRollbackError\n\t\t\terrsList = append(errsList, fmt.Errorf(\"objective %s: %w\", obj.ObjectiveID, err))\n\t\t}\n\n\t\t// Rate limiting between deletions\n\t\tif i > 0 {\n\t\t\ttime.Sleep(500 * time.Millisecond)\n\t\t}\n\t}\n\n\treturn errsList\n}\n\n// OKRBatchCreate batch creates objectives and their key results.\nvar OKRBatchCreate = common.Shortcut{\n\tService:     \"okr\",\n\tCommand:     \"+batch-create\",\n\tDescription: \"Batch create OKR objectives and key results with rollback on failure\",\n\tRisk:        \"write\",\n\tScopes:      []string{\"okr:okr.content:writeonly\"},","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/okr/okr_batch_create.go#L152-L188","documentation":"During rollback after a failed OKR batch create, each per-objective deletion failure is wrapped as `objective %s: %w`, preserving the delete error and the objective ID. These wraps are collected into an errors list and later assembled into a typed rollback error by buildRollbackError, so the user knows which objectives could not be cleaned up.","triggerScenarios":"A batch OKR create partially succeeded, rollback began, and deleteObjective failed for a specific objective ID — e.g. the objective was already deleted, permissions were revoked, or a rate limit hit that specific call.","commonSituations":"Partial batch failures where some objectives were created before the batch aborted; concurrent edits removed the objective mid-rollback; transient API outages or permission-scoped tokens that can create but not delete.","solutions":["Read the wrapped cause for the listed objective ID and fix the underlying delete failure (permissions, scopes, rate limits).","Manually delete the leftover objective IDs reported by the rollback error via the OKR delete command.","Retry the operation after resolving the cause; rollback errors indicate leftover state, not a problem with your input."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"err := batchCreate(ctx, runtime, objectives)\nif err != nil {\n    var rb *errs.TypedError\n    if errors.As(err, &rb) && strings.Contains(err.Error(), \"objective\") {\n        // parse leftover objective IDs from the wrapped message and delete them manually\n        for _, id := range extractObjectiveIDs(err.Error()) {\n            _ = deleteObjective(ctx, runtime, id)\n        }\n    }\n}","preventionTips":["Ensure the token has both create and delete scopes for OKR before batch runs.","Avoid concurrent mutations of the same OKR space during batch operations.","Handle partial-failure reports promptly to avoid orphaned objectives."],"tags":["okr","rollback","cleanup"],"backgroundTag":"cleanup-rollback-failed","analyzedSha":"7fd6ef3c07182257ce776cdc5a614e122d5bd4b3","analyzedAt":"2026-09-04T21:17:44.649Z","contentChangedAt":"2026-09-04T21:17:44.649Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}