Skip to content

feat(apps): friendly error for db commands on an app with no database - #2162

Open
chenxingyang1019 wants to merge 2 commits into
mainfrom
feat/db-no-database-hint
Open

feat(apps): friendly error for db commands on an app with no database#2162
chenxingyang1019 wants to merge 2 commits into
mainfrom
feat/db-no-database-hint

Conversation

@chenxingyang1019

@chenxingyang1019 chenxingyang1019 commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

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.

withAppsHint now special-cases this code:

  • message rewritten to a user-facing this app does not have a database yet (drops internal workspace / db-branch terms)
  • hint forced to a cloud-development recovery flow: +session-list/+session-create+chat (send the database requirement) → poll +session-get until latest_turn.status=completed → retry +db-table-list

The 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

500002759 is produced only by db endpoints, and every apps db command funnels through withAppsHint, 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 — no internal/ classification change.

Verification

Unit tests in common_test.go cover: code match rewrites message + forces hint; a preexisting upstream hint is overridden.

Live prod check against a no-database app (app_4k4a5fbdahm83):

command result
+db-table-list message rewritten + recovery hint injected
+db-table-get message rewritten
+db-execute --yes message rewritten (after reaching server)

go build ./... and go test ./shortcuts/apps/ pass.

Summary by CodeRabbit

  • Bug Fixes
    • Improved guidance for a specific database error by displaying a clearer message and cloud-development recovery instructions.
    • Preserved existing handling for other errors.

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.
@github-actions github-actions Bot added the size/M Single-domain feat or fix with limited business impact label Aug 3, 2026
@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The change adds constants and special handling for Spark error code 500002759. The handler standardizes its message and cloud-development recovery hint. Tests verify code preservation and precedence over caller-provided and upstream hints.

Changes

Spark no-database error handling

Layer / File(s) Summary
Standardized no-database error flow
shortcuts/apps/common.go, shortcuts/apps/common_test.go
The handler rewrites Spark error 500002759 with a standardized message and cloud-development recovery hint. Tests verify that the error code remains unchanged and that the recovery hint overrides other hints.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: r0bynzhu

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: a friendly error for database commands on apps without a database.
Description check ✅ Passed The description explains the motivation, implementation, scope, recovery flow, tests, and verification results, but does not use the repository template headings.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/db-no-database-hint

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between ba10438 and 4c0c4f1.

📒 Files selected for processing (2)
  • shortcuts/apps/common.go
  • shortcuts/apps/common_test.go

Comment on lines +61 to +78
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)
}
})

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 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

Comment thread shortcuts/apps/common.go
// 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>`"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 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.

@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

npm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@c6ac8c6726c1443f448bcf97a98fae8bdd29690e

🧩 Skill update

npx skills add larksuite/cli#feat/db-no-database-hint -y -g

@codecov

codecov Bot commented Aug 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.69%. Comparing base (0f29e03) to head (c6ac8c6).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Single-domain feat or fix with limited business impact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant