fix: migrate contact errors to typed taxonomy#1287
Conversation
📝 WalkthroughWalkthroughThe PR migrates the ChangesTyped Error Migration for Contact Domain
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 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 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.
🧹 Nitpick comments (1)
shortcuts/contact/contact_search_user_fanout.go (1)
222-349: 💤 Low valueConsider extracting repeated builder logic to reduce duplication.
All 8 switch cases share identical conditional-chaining logic (
WithCode,WithLogID,WithHint,WithRetryable). A small helper could cut this to ~30 lines while preserving behavior.♻️ Optional refactor sketch
// applyMetadata applies optional fields and returns an error interface. func applyMetadata(e interface { WithCode(int) interface{ WithLogID(string) interface{ WithHint(string, ...any) interface{ WithRetryable() error } } } // ... or define a shared TypedErrorBuilder interface in errs package }, first fanoutResult) error { if first.ErrCode != 0 { e = e.WithCode(first.ErrCode) } if first.ErrLog != "" { e = e.WithLogID(first.ErrLog) } if first.ErrHint != "" { e = e.WithHint("%s", first.ErrHint) } if first.ErrTry { return e.WithRetryable() } return e.(error) } func fanoutAllFailedError(first fanoutResult, msg string) error { subtype := first.ErrSub if subtype == "" { subtype = errs.SubtypeUnknown } var base interface{ ... } // typed error switch first.ErrCat { case errs.CategoryAuthentication: base = errs.NewAuthenticationError(subtype, "%s", msg) case errs.CategoryAuthorization: base = errs.NewPermissionError(subtype, "%s", msg) // ... other cases default: base = errs.NewAPIError(subtype, "%s", msg) } return applyMetadata(base, first) }This depends on whether the
errspackage exposes a common builder interface. If not, the current explicit approach is fine—just verbose.🤖 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/contact/contact_search_user_fanout.go` around lines 222 - 349, The fanoutAllFailedError function repeats identical builder chaining across each error case; extract that duplication by creating a helper (e.g., applyMetadata) that accepts the error builder returned from errs.NewAuthenticationError / NewPermissionError / NewConfigError / NewNetworkError / NewValidationError / NewSecurityPolicyError / NewInternalError / NewAPIError and the fanoutResult, applies WithCode, WithLogID, WithHint and WithRetryable conditionally, and returns the final error; you can implement a small interface for the builder either locally or in the errs package to type the helper, then simplify fanoutAllFailedError to only choose the base error by ErrCat and call applyMetadata(base, first).
🤖 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/contact/contact_search_user_fanout.go`:
- Around line 222-349: The fanoutAllFailedError function repeats identical
builder chaining across each error case; extract that duplication by creating a
helper (e.g., applyMetadata) that accepts the error builder returned from
errs.NewAuthenticationError / NewPermissionError / NewConfigError /
NewNetworkError / NewValidationError / NewSecurityPolicyError / NewInternalError
/ NewAPIError and the fanoutResult, applies WithCode, WithLogID, WithHint and
WithRetryable conditionally, and returns the final error; you can implement a
small interface for the builder either locally or in the errs package to type
the helper, then simplify fanoutAllFailedError to only choose the base error by
ErrCat and call applyMetadata(base, first).
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 117150c8-65bb-492e-9a4b-dd6c7e1b7ab0
📒 Files selected for processing (7)
.golangci.ymllint/errscontract/rule_no_legacy_common_helper_call.golint/errscontract/rule_no_legacy_envelope_literal.goshortcuts/contact/contact_get_user.goshortcuts/contact/contact_search_user.goshortcuts/contact/contact_search_user_fanout.goshortcuts/contact/contact_search_user_test.go
🚀 PR Preview Install Guide🧰 CLI updatenpm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@1bf7eef20b9975c4e1014619a1a8ca407c5ec37f🧩 Skill updatenpx skills add larksuite/cli#feat/errs-migrate-contact -y -g |
Codecov Report❌ Patch coverage is ❌ Your patch check has failed because the patch coverage (52.55%) is below the target coverage (60.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #1287 +/- ##
==========================================
- Coverage 70.33% 70.27% -0.06%
==========================================
Files 672 672
Lines 65322 65467 +145
==========================================
+ Hits 45941 46006 +65
- Misses 15728 15802 +74
- Partials 3653 3659 +6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
Migrate the contact shortcut domain to the typed
errs.*taxonomy and lock the domain into the migration guards. This keeps contact command failures structured and machine-actionable without changing successful output contracts.Changes
param/params.CallAPITyped/ClassifyAPIResponse, preserving typed API, network, auth, log_id, and code metadata.+search-user --queriespartial-failure payload shape stable while returning typed errors when every query fails.shortcuts/contact/to forbidigo and errscontract migrated-path guards, and update tests away from legacyoutput.ExitErrorassertions.Test Plan
/Users/bytedance/sdk/go1.23.10/bin/gofmt -l ./Users/bytedance/sdk/go1.23.10/bin/go test ./shortcuts/contact ./internal/errclass/Users/bytedance/sdk/go1.23.10/bin/go vet ./.../Users/bytedance/sdk/go1.23.10/bin/go run -C lint . ..go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.1.6 run --new-from-rev=origin/mainwith Go 1.23.10 on PATHgo mod tidyproduced nogo.mod/go.sumdiffmake unit-testcompleted contact and most packages, but failed in unrelated timeout tests:internal/binding TestResolveExecRef_MissingIDandinternal/selfupdate TestVerifyBinaryLookPath.lark-cli contact +get-user/+search-usererror paths are covered by targeted unit tests and migrated lint guards.Related Issues
Summary by CodeRabbit
Bug Fixes
Refactor
Tests