Skip to content

fix: use ErrValidation instead of fmt.Errorf in Validate paths#1001

Open
mengqiuzhen wants to merge 1 commit into
larksuite:mainfrom
mengqiuzhen:fix/validate-fmt-errorf-consistency
Open

fix: use ErrValidation instead of fmt.Errorf in Validate paths#1001
mengqiuzhen wants to merge 1 commit into
larksuite:mainfrom
mengqiuzhen:fix/validate-fmt-errorf-consistency

Conversation

@mengqiuzhen
Copy link
Copy Markdown
Contributor

@mengqiuzhen mengqiuzhen commented May 20, 2026

Summary

8 bare fmt.Errorf calls in Validate paths (across 3 files) returned unstructured errors without the standard type: validation JSON envelope and exit code 2. Replaced with output.ErrValidation for consistency with the rest of the codebase.

Changes

File Function Changes
shortcuts/sheets/lark_sheets_filter_views.go validateExpectedFlag 1 fmt.ErrorfErrValidation + import
shortcuts/mail/helpers.go validateSendTime, validateComposeInlineAndAttachments, validateEventFlags 6 fmt.ErrorfErrValidation
shortcuts/mail/signature_compose.go validateSignatureWithPlainText 1 fmt.ErrorfErrValidation + import

Verification

  • go build ./... — clean
  • go test ./shortcuts/sheets/... ./shortcuts/mail/... — pre-existing failures only (Windows CRLF golden files, sheets image paths), unrelated to this change

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor

    • Standardized validation error handling across mail and sheets commands for flag and format checks.
  • Bug Fixes

    • Validation now consistently surfaces user-facing errors for send-time checks, inline vs plain-text conflicts, incomplete event flag sets, signature/plain-text exclusivity, and invalid expected-JSON parsing.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 20, 2026

📝 Walkthrough

Walkthrough

Validation error returns in mail and sheets shortcuts were changed to use the centralized output.ErrValidation(...) helper instead of fmt.Errorf(...). Error texts are unchanged; the output import was added where needed.

Changes

Validation Error Standardization

Layer / File(s) Summary
Mail validation error refactoring
shortcuts/mail/helpers.go, shortcuts/mail/signature_compose.go
validateSendTime, validateComposeInlineAndAttachments, validateEventFlags, and validateSignatureWithPlainText now return output.ErrValidation(...) instead of fmt.Errorf(...); output import added.
Sheets filter validation refactoring
shortcuts/sheets/lark_sheets_filter_views.go
validateExpectedFlag now returns output.ErrValidation(...) for invalid --expected JSON-array parsing; output import added.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

size/M

Suggested reviewers

  • chanthuang
  • LuckyTerry

Poem

🐰 I hopped through code to tidy the trail,
Swapped scattered fmt for a single hale,
Errors aligned in one tidy row,
Now validations sing as they go,
A little hop, a cleaner tale.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main change: replacing fmt.Errorf with ErrValidation in validation code paths across multiple files.
Description check ✅ Passed The PR description includes all required sections with sufficient detail: summary explains the motivation, changes section lists affected files and functions, and verification confirms testing was performed.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

@github-actions github-actions Bot added domain/ccm PR touches the ccm domain domain/mail PR touches the mail domain size/L Large or sensitive change across domains or core paths labels May 20, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 21, 2026

Codecov Report

❌ Patch coverage is 87.50000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 67.67%. Comparing base (6840bb7) to head (1d0b996).
⚠️ Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
shortcuts/mail/signature_compose.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1001      +/-   ##
==========================================
+ Coverage   67.66%   67.67%   +0.01%     
==========================================
  Files         576      576              
  Lines       54510    54510              
==========================================
+ Hits        36885    36891       +6     
+ Misses      14566    14561       -5     
+ Partials     3059     3058       -1     

☔ View full report in Codecov by Sentry.
📢 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.

@github-actions
Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

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

🧩 Skill update

npx skills add mengqiuzhen/Feishu-cli#fix/validate-fmt-errorf-consistency -y -g

@mengqiuzhen mengqiuzhen force-pushed the fix/validate-fmt-errorf-consistency branch from 1d0b996 to 9d21388 Compare May 21, 2026 11:17
@fangshuyu-768
Copy link
Copy Markdown
Collaborator

CI is failing due to a goimports formatting error:

shortcuts/mail/signature_compose.go:12 — the newly added output import is not in the correct position. Please run goimports -w shortcuts/mail/signature_compose.go to fix the import ordering and push a new commit.

@mengqiuzhen mengqiuzhen force-pushed the fix/validate-fmt-errorf-consistency branch 2 times, most recently from 161a1f7 to 4569d96 Compare May 21, 2026 11:30
Replace 8 bare fmt.Errorf calls with output.ErrValidation across 3 files
so validation errors consistently return structured JSON (type: validation,
exit 2) matching the rest of the codebase.

Affected functions: validateExpectedFlag (sheets), validateSendTime,
validateComposeInlineAndAttachments, validateEventFlags (mail),
validateSignatureWithPlainText (mail)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
shortcuts/mail/signature_compose.go (1)

6-21: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Fix import ordering as requested by reviewer.

As noted in the PR comments, there's an import ordering issue in this file. Please run goimports -w shortcuts/mail/signature_compose.go to fix the import order before merging.

🤖 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/mail/signature_compose.go` around lines 6 - 21, The import block in
signature_compose.go is not ordered/formatted per project/goimports conventions;
run goimports to reorder and format imports (e.g., run `goimports -w
shortcuts/mail/signature_compose.go`) or manually reorder to group standard
library, third-party, and internal imports, then save; ensure the import list
around the package references like emlbuilder, signature, draftpkg, common, and
output remains correct and builds.
🤖 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.

Outside diff comments:
In `@shortcuts/mail/signature_compose.go`:
- Around line 6-21: The import block in signature_compose.go is not
ordered/formatted per project/goimports conventions; run goimports to reorder
and format imports (e.g., run `goimports -w
shortcuts/mail/signature_compose.go`) or manually reorder to group standard
library, third-party, and internal imports, then save; ensure the import list
around the package references like emlbuilder, signature, draftpkg, common, and
output remains correct and builds.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 78509dc5-6dfb-4162-9a10-b35b19e1601e

📥 Commits

Reviewing files that changed from the base of the PR and between 161a1f7 and 4569d96.

📒 Files selected for processing (3)
  • shortcuts/mail/helpers.go
  • shortcuts/mail/signature_compose.go
  • shortcuts/sheets/lark_sheets_filter_views.go

@mengqiuzhen
Copy link
Copy Markdown
Contributor Author

Thanks for the review! The goimports issue in signature_compose.go was fixed and force-pushed (commit 4569d96). The latest CI run is still waiting for approval — could you approve it to verify the fix passes?

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

Labels

domain/ccm PR touches the ccm domain domain/mail PR touches the mail domain size/L Large or sensitive change across domains or core paths

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants