fix: add stderr warnings when auto permission grant is skipped or fails#1015
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThe PR adds stderr warning messages in ChangesPermission Grant Failure Warnings
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
shortcuts/common/permission_grant.go (1)
75-81: ⚡ Quick winConsider caching the compacted error to avoid redundant computation.
The error is compacted twice—once for the result message (line 78) and once for the stderr output (line 80). Storing the result in a variable would eliminate the duplicate call.
♻️ Proposed refactor to cache the compacted error
if err != nil { + compactedErr := compactPermissionGrantError(err) result := buildPermissionGrantResult( PermissionGrantFailed, userOpenID, - fmt.Sprintf("Resource was created, but granting current user %s failed: %s. You can retry later or continue using bot identity.", permissionGrantPermMessage(), compactPermissionGrantError(err)), + fmt.Sprintf("Resource was created, but granting current user %s failed: %s. You can retry later or continue using bot identity.", permissionGrantPermMessage(), compactedErr), ) - fmt.Fprintf(runtime.IO().ErrOut, "⚠ 资源已创建,但自动授权失败:%s。您可以稍后重试或手动为资源授权。\n", compactPermissionGrantError(err)) + fmt.Fprintf(runtime.IO().ErrOut, "⚠ 资源已创建,但自动授权失败:%s。您可以稍后重试或手动为资源授权。\n", compactedErr) return result }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@shortcuts/common/permission_grant.go` around lines 75 - 81, The compactPermissionGrantError(err) call is executed twice; cache its result in a local variable (e.g., compactErr) and reuse it when building the PermissionGrantResult via buildPermissionGrantResult and when writing to runtime.IO().ErrOut with fmt.Fprintf; update the block containing buildPermissionGrantResult, permissionGrantPermMessage, compactPermissionGrantError, and the fmt.Fprintf call to reference the cached variable instead of calling compactPermissionGrantError twice.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@shortcuts/common/permission_grant.go`:
- Around line 75-81: The compactPermissionGrantError(err) call is executed
twice; cache its result in a local variable (e.g., compactErr) and reuse it when
building the PermissionGrantResult via buildPermissionGrantResult and when
writing to runtime.IO().ErrOut with fmt.Fprintf; update the block containing
buildPermissionGrantResult, permissionGrantPermMessage,
compactPermissionGrantError, and the fmt.Fprintf call to reference the cached
variable instead of calling compactPermissionGrantError twice.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: bd14196b-7e54-46de-ae90-3e0d7b750eb9
📒 Files selected for processing (1)
shortcuts/common/permission_grant.go
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1015 +/- ##
==========================================
+ Coverage 67.68% 67.71% +0.03%
==========================================
Files 576 575 -1
Lines 54547 54360 -187
==========================================
- Hits 36919 36811 -108
+ Misses 14567 14501 -66
+ Partials 3061 3048 -13 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
🚀 PR Preview Install Guide🧰 CLI updatenpm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@4c510d6bb740dded76f3cd8e1c0c8f537389e5d2🧩 Skill updatenpx skills add larksuite/cli#fix/permission-grant-stderr-warning -y -g |
d522e43 to
0ade710
Compare
When a resource is created with bot identity, the CLI attempts to auto-grant full_access to the current user. If the user open_id is missing or the grant API call fails, the result was only written to the JSON permission_grant field and easily overlooked. Changes: - Add stderr warnings when auto-grant is skipped or fails - Add 'hint' field to permission_grant JSON output with failure reason and actionable next step (e.g. auth login, check scope, retry) - Add end-to-end skipped/failed tests across all affected shortcuts (doc, drive, sheets, slides, wiki, markdown, base) Closes #963
0ade710 to
4c510d6
Compare
…1015) When a resource is created with bot identity, the CLI attempts to auto-grant full_access to the current user. If the user open_id is missing or the grant API call fails, the result was only written to the JSON permission_grant field and easily overlooked. Changes: - Add stderr warnings when auto-grant is skipped or fails - Add 'hint' field to permission_grant JSON output with failure reason and actionable next step (e.g. auth login, check scope, retry) - Add end-to-end skipped/failed tests across all affected shortcuts (doc, drive, sheets, slides, wiki, markdown, base) Closes larksuite#963
Summary
Closes #963
When a resource is created with bot identity, the CLI attempts to auto-grant
full_accessto the current user. However, if the useropen_idis missing or the grant API call fails, the result was only written to the JSONpermission_grantfield and easily overlooked by users.This PR adds visible stderr warnings in both cases so users are clearly informed and can take action.
Changes
permission_grant.go:51): print a stderr warning advising the user to runlark-cli auth loginor grant permission manually.permission_grant.go:80): print a stderr warning including the error reason, advising the user to retry later or grant permission manually.Impact
All 12 shortcuts that call
AutoGrantCurrentUserDrivePermission(docs, drive, sheets, slides, base, markdown, wiki) automatically benefit — no per-shortcut changes needed.Test
All existing tests pass without modification:
TestDocsCreateV2BotAutoGrantSkippedWithoutCurrentUserTestDocsCreateV2BotAutoGrantFailureDoesNotFailCreateTestDocsCreateV1WikiSpaceAutoGrantFailureTestDriveUploadBotAutoGrantSuccessTestDriveUploadUserSkipsPermissionGrantAugmentationSummary by CodeRabbit