Skip to content

feat(okr,whiteboard): surface input errors as typed error envelopes#1236

Open
evandance wants to merge 1 commit into
mainfrom
feat/errs-migrate-okr-whiteboard
Open

feat(okr,whiteboard): surface input errors as typed error envelopes#1236
evandance wants to merge 1 commit into
mainfrom
feat/errs-migrate-okr-whiteboard

Conversation

@evandance
Copy link
Copy Markdown
Collaborator

@evandance evandance commented Jun 2, 2026

Summary

Migrates input-side and local-side errors in the okr and whiteboard commands to
the typed errs.* envelope. Invalid flags, malformed input payloads, and
output-file conflicts now carry a stable category, subtype, and the offending
flag, so scripts and agents can branch on error shape and exit code instead of
scraping message strings. No success-path behavior changes.

This is stage 1 of 2. The raw-API boundary stays on the existing envelopes under
TODO(errs-migrate) markers and converts in a follow-up once the shared typed
API path (runtime.CallAPITyped / ClassifyAPIResponse) lands on main.

Changes

  • okr (47 sites) and whiteboard (14 sites): legacy output.Err* / common.FlagErrorf
    errs.NewValidationError(SubtypeInvalidArgument).WithParam("--flag") and
    errs.NewInternalError(...) for local file I/O.
  • Added dual-shape tests asserting the typed envelope (errors.As / errs.ProblemOf,
    subtype, offending param) survives command dispatch.
  • 13 raw-API sites left under TODO(errs-migrate) for the stage-2 follow-up.

Test Plan

  • gofmt -l, go vet, go build ./...: clean
  • go test ./shortcuts/okr/... ./shortcuts/whiteboard/...: pass
  • golangci-lint run --new-from-rev=origin/main (both domains): 0 issues
  • errscontract (go run -C lint . ..): 0 violations

Related Issues

Part of the cli-errors-refactor domain migration.

Summary by CodeRabbit

  • Improvements

    • Enhanced error reporting across OKR and Whiteboard CLI commands with more detailed parameter information, making it easier to identify which flags caused validation failures.
  • Tests

    • Added test coverage for improved error handling and parameter validation in OKR cycle detail, whiteboard query, and whiteboard update commands.

Invalid flags, malformed input payloads, and output-file conflicts in the
okr and whiteboard commands now return structured error envelopes — each
carrying a stable category, subtype, and the offending flag — instead of
flat strings. Scripts and agents can branch on the error shape and exit
code rather than scraping messages.

API-response errors in these commands keep the existing envelopes for now;
they convert in a follow-up once the shared typed API path is available.
@evandance evandance added the enhancement New feature or request label Jun 2, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 2, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

This PR systematically migrates CLI validation error handling across OKR and whiteboard shortcuts from legacy helpers (common.FlagErrorf, output.ErrValidation) to a structured errs.NewValidationError API with parameter metadata. Test coverage verifies typed error behavior. TODO comments mark future API migration boundaries.

Changes

CLI Validation Error Type Migration

Layer / File(s) Summary
OKR Cycle Commands
shortcuts/okr/okr_cycle_detail.go, shortcuts/okr/okr_cycle_detail_test.go, shortcuts/okr/okr_cycle_list.go
--cycle-id, --user-id-type, and --time-range validation failures now return errs.NewValidationError(...).WithParam(...) instead of common.FlagErrorf. New test TestCycleDetailValidate_TypedError verifies error type, subtype, and parameter binding. TODO comments document planned migration to runtime.CallAPITyped.
OKR Image Upload and Progress Commands
shortcuts/okr/okr_image_upload.go, shortcuts/okr/okr_progress_create.go, shortcuts/okr/okr_progress_delete.go, shortcuts/okr/okr_progress_get.go, shortcuts/okr/okr_progress_list.go, shortcuts/okr/okr_progress_update.go
All argument validation (--file, --target-id, --progress-id, --content, --progress-percent, --progress-status, --user-id-type, --department-id-type) unified to use errs.NewValidationError(...).WithParam(...) with consistent SubtypeInvalidArgument. Parameter parsing functions and Validate methods consistently apply the new error type. TODO comments mark API boundary migration plans.
Whiteboard Commands
shortcuts/whiteboard/whiteboard_query.go, shortcuts/whiteboard/whiteboard_query_test.go, shortcuts/whiteboard/whiteboard_update.go, shortcuts/whiteboard/whiteboard_update_test.go
WhiteboardQuery.Validate and WhiteboardUpdate.Validate migrate validation errors to errs.NewValidationError(...).WithParam(...) for --output, --output_as, --idempotent-token, --input_format, and --source. JSON marshalling and file-existence failures use errs.NewInternalError(...). New tests TestWhiteboardQuery_Validate_TypedErrors and TestWhiteboardUpdate_Validate_TypedErrors with helper assertValidationParam verify typed error metadata. TODO comments document API migration routing.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • larksuite/cli#574: Overlapping refactoring of OKR shortcut validation logic in okr_image_upload.go and okr_progress_* commands.

Suggested labels

size/L, domain/ccm

Suggested reviewers

  • kongenpei
  • zhangzq0
  • zgz2048

Poem

🐰 Errors now speak with types so clear,
Where flags and subtypes appear,
No more strings of muddled fate—
Validation errors validate!
With parameters bound, they guide the way,
Through OKR and whiteboard all day! 📋✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% 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 accurately describes the main change: migrating input/validation errors in okr and whiteboard commands to typed error envelopes.
Description check ✅ Passed The description includes all required sections: Summary, Changes, Test Plan, and Related Issues. It provides detailed context about the migration, scope, test coverage, and future work.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/errs-migrate-okr-whiteboard

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 the size/L Large or sensitive change across domains or core paths label Jun 2, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 2, 2026

Codecov Report

❌ Patch coverage is 45.61404% with 31 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.22%. Comparing base (04932c2) to head (0b7e027).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
shortcuts/okr/okr_progress_create.go 33.33% 8 Missing ⚠️
shortcuts/okr/okr_progress_update.go 36.36% 7 Missing ⚠️
shortcuts/whiteboard/whiteboard_query.go 42.85% 4 Missing ⚠️
shortcuts/okr/okr_image_upload.go 40.00% 3 Missing ⚠️
shortcuts/whiteboard/whiteboard_update.go 57.14% 3 Missing ⚠️
shortcuts/okr/okr_progress_list.go 60.00% 2 Missing ⚠️
shortcuts/okr/okr_cycle_detail.go 50.00% 1 Missing ⚠️
shortcuts/okr/okr_cycle_list.go 66.66% 1 Missing ⚠️
shortcuts/okr/okr_progress_delete.go 50.00% 1 Missing ⚠️
shortcuts/okr/okr_progress_get.go 66.66% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1236   +/-   ##
=======================================
  Coverage   69.22%   69.22%           
=======================================
  Files         635      635           
  Lines       59687    59689    +2     
=======================================
+ Hits        41320    41322    +2     
  Misses      15033    15033           
  Partials     3334     3334           

☔ 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

github-actions Bot commented Jun 2, 2026

🚀 PR Preview Install Guide

🧰 CLI update

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

🧩 Skill update

npx skills add larksuite/cli#feat/errs-migrate-okr-whiteboard -y -g

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.

Actionable comments posted: 1

♻️ Duplicate comments (1)
shortcuts/okr/okr_progress_update.go (1)

108-110: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Grammar: "must provided" → "must be provided".

Same wording issue as okr_progress_create.go Line 158.

✏️ Proposed fix
-				return errs.NewValidationError(errs.SubtypeInvalidArgument, "--progress-percent must provided with --progress-status").WithParam("--progress-percent")
+				return errs.NewValidationError(errs.SubtypeInvalidArgument, "--progress-percent must be provided with --progress-status").WithParam("--progress-percent")
🤖 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/okr/okr_progress_update.go` around lines 108 - 110, Update the
validation error message that currently reads "--progress-percent must provided
with --progress-status" to correct grammar: "--progress-percent must be provided
with --progress-status". Change the string in the code path where
runtime.Str("progress-percent") == "" (the errs.NewValidationError(...) call)
and make the identical change in the similar message in okr_progress_create.go
to keep wording consistent.
🤖 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/okr/okr_progress_create.go`:
- Around line 157-159: Update the user-facing validation error message to
correct the grammar: change the string returned when
runtime.Str("progress-percent") is empty inside the create handler (the block
that returns errs.NewValidationError(...).WithParam("--progress-percent")) from
" --progress-percent must provided with --progress-status" to "
--progress-percent must be provided with --progress-status" so the message reads
" --progress-percent must be provided with --progress-status".

---

Duplicate comments:
In `@shortcuts/okr/okr_progress_update.go`:
- Around line 108-110: Update the validation error message that currently reads
"--progress-percent must provided with --progress-status" to correct grammar:
"--progress-percent must be provided with --progress-status". Change the string
in the code path where runtime.Str("progress-percent") == "" (the
errs.NewValidationError(...) call) and make the identical change in the similar
message in okr_progress_create.go to keep wording consistent.
🪄 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

Run ID: 905c6ac6-b988-44a3-b7aa-4fed629d6643

📥 Commits

Reviewing files that changed from the base of the PR and between c8e205e and 0b7e027.

📒 Files selected for processing (13)
  • shortcuts/okr/okr_cycle_detail.go
  • shortcuts/okr/okr_cycle_detail_test.go
  • shortcuts/okr/okr_cycle_list.go
  • shortcuts/okr/okr_image_upload.go
  • shortcuts/okr/okr_progress_create.go
  • shortcuts/okr/okr_progress_delete.go
  • shortcuts/okr/okr_progress_get.go
  • shortcuts/okr/okr_progress_list.go
  • shortcuts/okr/okr_progress_update.go
  • shortcuts/whiteboard/whiteboard_query.go
  • shortcuts/whiteboard/whiteboard_query_test.go
  • shortcuts/whiteboard/whiteboard_update.go
  • shortcuts/whiteboard/whiteboard_update_test.go

Comment on lines 157 to 159
if v := runtime.Str("progress-percent"); v == "" {
return common.FlagErrorf("--progress-percent must provided with --progress-status")
return errs.NewValidationError(errs.SubtypeInvalidArgument, "--progress-percent must provided with --progress-status").WithParam("--progress-percent")
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Grammar: "must provided" → "must be provided".

User-facing error string reads ungrammatically.

✏️ Proposed fix
-			return errs.NewValidationError(errs.SubtypeInvalidArgument, "--progress-percent must provided with --progress-status").WithParam("--progress-percent")
+			return errs.NewValidationError(errs.SubtypeInvalidArgument, "--progress-percent must be provided with --progress-status").WithParam("--progress-percent")
🤖 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/okr/okr_progress_create.go` around lines 157 - 159, Update the
user-facing validation error message to correct the grammar: change the string
returned when runtime.Str("progress-percent") is empty inside the create handler
(the block that returns
errs.NewValidationError(...).WithParam("--progress-percent")) from "
--progress-percent must provided with --progress-status" to " --progress-percent
must be provided with --progress-status" so the message reads "
--progress-percent must be provided with --progress-status".

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

Labels

enhancement New feature or request size/L Large or sensitive change across domains or core paths

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant