feat(apps): friendly error for db commands on an app with no database - #2162
feat(apps): friendly error for db commands on an app with no database#2162chenxingyang1019 wants to merge 2 commits into
Conversation
Server code 500002759 (a db command run against an app that has not initialized a database yet) previously surfaced with an internal-term message and no actionable next step. withAppsHint now special-cases this code: it rewrites the message to a user-facing "this app does not have a database yet" and forces a cloud-development recovery hint (session-list/create -> chat -> poll session-get -> retry). Because every apps db command funnels through withAppsHint and this code is db-endpoint-specific, the whole db command family is covered without per-command changes.
📝 WalkthroughWalkthroughThe change adds constants and special handling for Spark error code ChangesSpark no-database error handling
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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.
Actionable comments posted: 2
🤖 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.
Inline comments:
In `@shortcuts/apps/common_test.go`:
- Around line 61-78: Extend the “no-database code rewrites message and forces
cloud-dev hint” test to assert that p.Category and p.Subtype retain the input
error’s classification, and assert out == in to verify withAppsHint returns the
original error instance. Keep the existing message, hint, and code assertions
unchanged.
In `@shortcuts/apps/common.go`:
- Line 43: Update the final instruction in appNoDatabaseHint to tell the user to
retry the original database command rather than hard-coding +db-table-list.
Preserve the existing session creation, message submission, and polling
instructions so withAppsHint can recover whichever database command failed.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 743891d8-f3d1-4769-814d-fe8865198d75
📒 Files selected for processing (2)
shortcuts/apps/common.goshortcuts/apps/common_test.go
| t.Run("no-database code rewrites message and forces cloud-dev hint", func(t *testing.T) { | ||
| // Raw upstream carries internal-term message and no hint. | ||
| in := errs.NewAPIError(errs.SubtypeUnknown, "workspace has no db branch").WithCode(appNoDatabaseCode) | ||
| out := withAppsHint(in, "generic db hint") | ||
| p, ok := errs.ProblemOf(out) | ||
| if !ok { | ||
| t.Fatalf("returned error is not typed: %T", out) | ||
| } | ||
| if p.Message != appNoDatabaseMessage { | ||
| t.Errorf("Message = %q, want rewritten %q", p.Message, appNoDatabaseMessage) | ||
| } | ||
| if p.Hint != appNoDatabaseHint { | ||
| t.Errorf("Hint = %q, want cloud-dev hint (not the generic caller hint)", p.Hint) | ||
| } | ||
| if p.Code != appNoDatabaseCode { | ||
| t.Errorf("Code mutated: got %d, want %d", p.Code, appNoDatabaseCode) | ||
| } | ||
| }) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Assert preserved classification and error identity.
This test checks only Code. It does not verify that Category and Subtype remain unchanged. It also does not verify that withAppsHint returns the original error. Assert p.Category, p.Subtype, and out == in so a replacement error that drops classification or a wrapped cause fails the test.
As per coding guidelines, error-path tests must assert typed metadata and verify cause preservation.
🤖 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/apps/common_test.go` around lines 61 - 78, Extend the “no-database
code rewrites message and forces cloud-dev hint” test to assert that p.Category
and p.Subtype retain the input error’s classification, and assert out == in to
verify withAppsHint returns the original error instance. Keep the existing
message, hint, and code assertions unchanged.
Source: Coding guidelines
| // execute it without matching natural-language error text. Adding a database is | ||
| // a cloud write: a failed read alone does not authorize it — confirm with the | ||
| // user before starting a +chat. | ||
| const appNoDatabaseHint = "ask the user whether to add a database through Miaoda cloud development; if confirmed, run `lark-cli apps +session-list --app-id <app_id>` and reuse an active session, or run `lark-cli apps +session-create --app-id <app_id>`; send the database requirement with `lark-cli apps +chat --app-id <app_id> --session-id <session_id> --message \"<database requirement>\"`, poll `lark-cli apps +session-get --app-id <app_id> --session-id <session_id>` until `latest_turn.status=completed`, then retry `lark-cli apps +db-table-list --app-id <app_id>`" |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Retry the original database command.
Line 43 hard-codes +db-table-list as the retry action. withAppsHint handles all apps database commands. If the failed command was another database command, the recovery flow changes the requested operation instead of retrying it. Replace this final instruction with a request to retry the original database command.
Based on PR objectives, the recovery flow must retry the database command that failed.
🤖 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/apps/common.go` at line 43, Update the final instruction in
appNoDatabaseHint to tell the user to retry the original database command rather
than hard-coding +db-table-list. Preserve the existing session creation, message
submission, and polling instructions so withAppsHint can recover whichever
database command failed.
🚀 PR Preview Install Guide🧰 CLI updatenpm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@c6ac8c6726c1443f448bcf97a98fae8bdd29690e🧩 Skill updatenpx skills add larksuite/cli#feat/db-no-database-hint -y -g |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2162 +/- ##
=======================================
Coverage 75.69% 75.69%
=======================================
Files 942 942
Lines 100079 100083 +4
=======================================
+ Hits 75750 75754 +4
Misses 18537 18537
Partials 5792 5792 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
What
Server code
500002759— a db command run against an app that has not initialized a database yet — previously surfaced with an internal-term message and no actionable next step.withAppsHintnow special-cases this code:this app does not have a database yet(drops internal workspace / db-branch terms)+session-list/+session-create→+chat(send the database requirement) → poll+session-getuntillatest_turn.status=completed→ retry+db-table-listThe override is unconditional for this code (it also replaces any upstream hint), since the recovery flow is more actionable than any generic hint.
Why this placement
500002759is produced only by db endpoints, and every apps db command funnels throughwithAppsHint, so the whole db command family (+db-table-list/-table-get/-execute/-data-import|export/-changelog-list/-audit-*/-quota-get/-recovery-*/-env-*) is covered without per-command changes. Kept entirely in the apps shortcut layer — nointernal/classification change.Verification
Unit tests in
common_test.gocover: code match rewrites message + forces hint; a preexisting upstream hint is overridden.Live prod check against a no-database app (
app_4k4a5fbdahm83):+db-table-list+db-table-get+db-execute --yesgo build ./...andgo test ./shortcuts/apps/pass.Summary by CodeRabbit