feat(common): emit typed validation errors from shared shortcut pre-checks#1242
Conversation
📝 WalkthroughWalkthroughAdds typed validation/error helpers, migrates shortcut input/ID validators and IO wrappers to typed errors with params/causes, and enforces removal of legacy ChangesTyped Validation Error Enforcement and Migration
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 |
🚀 PR Preview Install Guide🧰 CLI updatenpm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@9268e4a16b74393ba1824bce69bb9a54b7c0d935🧩 Skill updatenpx skills add larksuite/cli#feat/errs-common-infra -y -g |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #1242 +/- ##
==========================================
+ Coverage 69.22% 69.27% +0.04%
==========================================
Files 639 639
Lines 59798 59923 +125
==========================================
+ Hits 41395 41510 +115
Misses 15058 15058
- Partials 3345 3355 +10 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
82b85db to
22326f9
Compare
…hecks Input pre-check failures shared by every shortcut — @file/stdin input resolution, enum validation, and unsupported --dry-run — now leave the CLI as typed validation envelopes naming the offending flag, so scripts and AI agents can branch on `param` instead of parsing prose. Wire type, exit code, and message text are unchanged; the new fields are additive. The shared layer also gains typed replacements for its legacy error-producing helpers, so each business domain can migrate to typed errors without rebuilding common plumbing, and a path-scoped lint guard keeps migrated domains from sliding back. Changes: - Shared pre-check failures (input flags, enum values, dry-run support) return typed validation errors carrying the offending flag as `param`. - Every legacy error-producing helper in shortcuts/common has a typed replacement that preserves the existing message text: validation and flag-group checks, chat/user ID validation (callers name the flag so `param` is ground truth), "me" open-id resolution, safe-path checks, input-stat and save-error wrapping. Legacy helpers stay for not-yet-migrated domains, marked deprecated — including the legacy API-result classifier, whose typed route is runtime.CallAPITyped. - A new errscontract rule rejects legacy common-helper calls on migrated paths, so a migrated domain cannot silently reintroduce legacy envelopes; drive is the first locked path and its last legacy ID-helper calls are replaced.
22326f9 to
9268e4a
Compare
…hecks (larksuite#1242) Input pre-check failures shared by every shortcut — @file/stdin input resolution, enum validation, and unsupported --dry-run — now leave the CLI as typed validation envelopes naming the offending flag, so scripts and AI agents can branch on `param` instead of parsing prose. Wire type, exit code, and message text are unchanged; the new fields are additive. The shared layer also gains typed replacements for its legacy error-producing helpers, so each business domain can migrate to typed errors without rebuilding common plumbing, and a path-scoped lint guard keeps migrated domains from sliding back. Changes: - Shared pre-check failures (input flags, enum values, dry-run support) return typed validation errors carrying the offending flag as `param`. - Every legacy error-producing helper in shortcuts/common has a typed replacement that preserves the existing message text: validation and flag-group checks, chat/user ID validation (callers name the flag so `param` is ground truth), "me" open-id resolution, safe-path checks, input-stat and save-error wrapping. Legacy helpers stay for not-yet-migrated domains, marked deprecated — including the legacy API-result classifier, whose typed route is runtime.CallAPITyped. - A new errscontract rule rejects legacy common-helper calls on migrated paths, so a migrated domain cannot silently reintroduce legacy envelopes; drive is the first locked path and its last legacy ID-helper calls are replaced.
Summary
Shared pre-check failures that every shortcut emits —
@file/stdin input resolution, enum validation, and unsupported--dry-run— now leave the CLI as typederrs.*validation envelopes carryingsubtype: invalid_argumentand the offending flag asparam. Wiretype, exit code, and message text are unchanged; the new fields are additive, so existing consumers and not-yet-migrated domains are unaffected.The shared
commonlayer also gains typed replacements for its legacy error-producing helpers — validation and flag-group checks, chat/user ID validation, "me" open-id resolution, safe-path checks, input-stat and save-error wrapping, and the API-result classifier — so business domains can adopt typed errors without rebuilding common plumbing. Legacy helpers keep their current behavior and stay available, marked deprecated. A path-scoped lint rule rejects any reference to a legacy helper on migrated paths;shortcuts/drive/is the first locked path, and each domain adds itself to the list when it migrates.Scope: this PR covers the shared validation/file/API-result helper layer and the shared pre-checks. Shared business helpers (
UploadDriveMediaAll/Multipart,ParseDriveMediaUploadResponse,FetchDriveMeta*,ResolveSavePath,EnsureScopes) keep their current error behavior and are not part of this change.Changes
param—shortcuts/common/runner.go.ValidationErrorf,MutuallyExclusiveTyped/AtLeastOneTyped/ExactlyOneTyped,ValidatePageSizeTyped,ValidateChatIDTyped/ValidateUserIDTyped(flag name as a parameter soparamreflects the caller's flag),ResolveOpenIDsTyped,ValidateSafePathTyped,RejectDangerousCharsTyped,WrapInputStatErrorTyped,WrapSaveErrorTyped—shortcuts/common/.HandleApiResult) carry deprecation notices pointing at their typed replacements; runtime behavior unchanged.no_legacy_common_helper_call: rejects any reference — direct calls and function-value references alike — to the 13 legacy helpers on migrated paths, with per-helper replacement suggestions; aliased and dot imports are covered —lint/errscontract/.shortcuts/drive/drive_search.go.WrapSaveErrorTypedalways emits the canonicalinternalwire type; call sites moving offWrapSaveErrorByCategory's custom categories (io,api_error) change their envelopetypefield when they migrate.Test Plan
gofmt -l .,go vet ./...,go build ./..., golangci-lint (--new-from-rev=origin/main, 0 issues), errscontract scan (go run -C lint . ..), unit tests (81 pkgs) + lint module tests,git diff --check, incremental deadcode clean*errs.ValidationErrorsubtype +param(including flag-groupparams, safe-path symlink escape, save-error path/mkdir classification,meresolution); guard tests cover all 13 helpers plus aliased imports, dot imports, and function-value references; non-migrated paths passparamon stdin/file/enum/dry-run failures with messages unchangedRelated Issues