Skip to content

fix(apps): detect the no-database failure by code or message - #2217

Open
chenxingyang1019 wants to merge 2 commits into
mainfrom
fix/apps-no-database-error-match
Open

fix(apps): detect the no-database failure by code or message#2217
chenxingyang1019 wants to merge 2 commits into
mainfrom
fix/apps-no-database-error-match

Conversation

@chenxingyang1019

@chenxingyang1019 chenxingyang1019 commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

Why

withAppsHint keyed the "this app has no database yet" special case on a single business code, 500002759. The server has since renumbered that case to 400002465, so the branch no longer fires. Observed on BOE against a database-less app:

intended current, on main
message this app does not have a database yet get workspace id failed by app id
hint full cloud-development recovery steps generic "verify --app-id"

The raw message is internal vocabulary (workspace ↔ app-id mapping) — rewriting it is precisely why the special case exists. Worse, the generic hint suggests +db-env-create, which is not a valid next step for an app that has no database at all.

Nothing caught this: no compile error, and the unit tests compare against the same constant they set, so they pass either way. The dry-run E2E never reaches a live server, so the only way to observe it is running a db command against a real database-less app.

What changed

Detect on code OR message. Both known codes are kept (400002465 current, 500002759 legacy), plus narrow lowercase markers of the server's internal wording. The channels have opposite failure modes — a code is precise but gets renumbered, a message survives renumbering but breaks on rewording or localization — so requiring either means one channel changing degrades nothing, and only a simultaneous change of both regresses.

Markers stay deliberately narrow. "no db branch" must not swallow env-pull's "invalid db branch" case, which needs its own hint; a comment records that widening them requires a test proving the neighbours still pass through.

Verification

Unit: go test ./shortcuts/apps/ — 3 new subtests cover the legacy code, an unknown code matched by message (case-insensitive and substring), and negative controls proving "invalid db branch: dev", "数据表格不存在" and "permission denied" keep the caller's hint.

Live, on BOE lane boe_lark_cli_db_file:

  • database-less app → rewritten message and the full recovery hint are both restored
  • numerically adjacent 400002469 ("table does not exist") → not hijacked, keeps its own hint
  • normal +db-table-list → unaffected

go build ./... and go test ./tests/cli_e2e/apps/ pass. The BOE db regression suites (cli_e2e.sh, db_data_e2e.sh) were run against this build; see the review note below on their 3 pre-existing failures.

Notes for review

  • No behavior change outside the no-database branch: classification (type/subtype/code/log_id) and the cause chain are untouched, as the existing tests assert.
  • Not addressed here, flagged for follow-up: apps_env_pull.go and apps_env.go discriminate purely on English message text, which is the mirror-image fragility — a server rewording or a switch to Chinese silently disables them.

Summary by CodeRabbit

  • Bug Fixes

    • Improved detection of database initialization issues across current and legacy error formats.
    • Added clearer recovery guidance for applicable cloud development environments.
    • Preserved original error messages and custom guidance for unrelated database failures.
    • Improved handling of missing or empty error details.
  • Tests

    • Added coverage for legacy error codes, case-insensitive matching, embedded server messages, unrelated database errors, and missing error input.

@github-actions github-actions Bot added the size/M Single-domain feat or fix with limited business impact label Aug 6, 2026
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 159eecde-143e-4228-9c57-b109c71601a9

📥 Commits

Reviewing files that changed from the base of the PR and between 4d1a04a and 2f82630.

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

📝 Walkthrough

Walkthrough

The app error flow detects database initialization failures through current and legacy codes or matching server messages. withAppsHint applies the recovery message and hint. Tests cover case variations, substrings, wrapped causes, unrelated errors, and nil input.

Changes

Database error detection and recovery

Layer / File(s) Summary
Database error detector and recovery hint
shortcuts/apps/common.go
The detector recognizes current and legacy database codes and lowercase server-message markers. withAppsHint uses the detector.
Recovery flow validation
shortcuts/apps/common_test.go
Tests verify message-based and legacy-code detection, preserved causes and classification, recovery hints, unrelated failures, and nil input.

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

Possibly related PRs

  • larksuite/cli#2162: Introduced the withAppsHint no-database error handling that this change extends.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: detecting no-database failures by business code or server message.
Description check ✅ Passed The description explains the motivation, changes, verification, regression coverage, and scope; it does not include a separate Related Issues section.
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 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/apps-no-database-error-match

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 98-135: Extend the affected tests around the legacy, unknown-code,
and unrelated-failure cases to assert the resulting error’s expected Category
and Subtype, retaining each input error for comparison. Add a wrapped-cause
scenario and verify the error returned through errs.ProblemOf preserves that
cause chain, without asserting a nonexistent Param field.

In `@tests/cli_e2e/apps/apps_env_pull_live_test.go`:
- Around line 31-33: Remove the LARKSUITE_CLI_CONFIG_DIR requirement from the
setup of this live workflow test. Use the established live-token gate for
skipping unavailable credentials, while retaining
LARK_CLI_E2E_APPS_ENV_PULL_APP_ID as the fixture gate.
🪄 Autofix

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: 3863f1f6-3e80-4aa0-8922-c48d80da1c81

📥 Commits

Reviewing files that changed from the base of the PR and between 164d3cc and d4162da.

📒 Files selected for processing (4)
  • shortcuts/apps/common.go
  • shortcuts/apps/common_test.go
  • tests/cli_e2e/apps/apps_env_pull_live_test.go
  • tests/cli_e2e/apps/coverage.md

Comment thread shortcuts/apps/common_test.go
Comment thread tests/cli_e2e/apps/apps_env_pull_live_test.go Outdated
@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

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

🧩 Skill update

npx skills add larksuite/cli#fix/apps-no-database-error-match -y -g

The recovery flow for "db command against an app that has no database"
keyed on one business code (500002759). The server has since renumbered
that case to 400002465, which silently disabled the flow: users now see
the raw internal message ("get workspace id failed by app id") and lose
the cloud-development recovery steps entirely.

Nothing caught the regression. There is no compile error, the unit tests
compare against the same constant they set, and the dry-run E2E never
reaches a live server — the failure is only observable by running a db
command against a real database-less app.

Detect on code OR message instead. Both known codes are kept, plus narrow
lowercase markers of the server's internal wording. The two channels have
opposite failure modes: a code is precise but gets renumbered, a message
survives renumbering but breaks on rewording or localization. Requiring
either to match means one channel changing degrades nothing, and only a
simultaneous change of both regresses.

Markers stay deliberately narrow. "no db branch" in particular must not
also swallow env-pull's "invalid db branch" case, which needs its own
hint; a comment records that widening them requires a test proving the
neighbours still pass through.

Verified on BOE against an app with no database: the rewritten message and
the recovery hint are both restored. Negative controls confirm the
numerically adjacent 400002469 ("table does not exist") and an unrelated
permission failure keep their own hints.
@codecov

codecov Bot commented Aug 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.22%. Comparing base (9759167) to head (2f82630).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2217      +/-   ##
==========================================
+ Coverage   76.08%   76.22%   +0.13%     
==========================================
  Files         983      986       +3     
  Lines      103429   104278     +849     
==========================================
+ Hits        78692    79482     +790     
  Misses      18752    18752              
- Partials     5985     6044      +59     

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

@chenxingyang1019
chenxingyang1019 force-pushed the fix/apps-no-database-error-match branch from d4162da to 4d1a04a Compare August 6, 2026 11:52
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@chenxingyang1019 chenxingyang1019 changed the title fix(apps): detect the no-database failure by code or message, and add +env-pull live E2E fix(apps): detect the no-database failure by code or message Aug 6, 2026
Review feedback: the new subtests checked only Message and Hint, so a
change that reclassified the failure — or replaced the error value and
dropped the cause chain — would still have passed.

Each case now asserts Category, Subtype and Code are untouched by the
rewrite, and that the helper returns the same error value. Inputs use a
concrete subtype rather than Unknown, so a clobbered classification is
actually observable. One new case wraps a cause and asserts errors.Is
still finds it through the rewrite.

Also covers the predicate's defensive nil guard, which withAppsHint cannot
reach on its own (ProblemOf returns ok=false for untyped errors), closing
the two uncovered lines codecov flagged. Both withAppsHint and
isAppNoDatabaseError are now at 100%.
@chenxingyang1019

Copy link
Copy Markdown
Collaborator Author

Addressed the two review threads:

common_test.go — assert the full typed-error contract. Valid, fixed in 2f82630. Each of the new cases now asserts Category, Subtype and Code survive the rewrite and that the helper returns the same error value; inputs use a concrete subtype instead of Unknown so a clobbered classification is observable. Added a wrapped-cause case asserting errors.Is still finds the cause through the rewrite. Did not assert Param — as noted, it does not apply to these API errors.

apps_env_pull_live_test.go — do not require an isolated config dir. No longer applicable: that file was dropped from this PR (the E2E belongs in the local BOE regression suite, not the repo), so the PR is now scoped to the no-database detection fix alone.

Also closed the codecov gap the report flagged (2 uncovered lines): withAppsHint and isAppNoDatabaseError are both at 100% now.

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