fix(sheets): add missing JSON unmarshal error handling in dry-run mode#935
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughTwo DryRun handlers now explicitly assign the result of json.Unmarshal to ChangesDryRun explicit json.Unmarshal discard
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 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.
Pull request overview
This PR aims to make sheets +set-style and sheets +batch-set-style dry-run behavior consistent with real execution by handling JSON unmarshal failures for --style/--data instead of silently proceeding.
Changes:
- Add JSON unmarshal error checks in
SheetSetStyle.DryRunfor--style. - Add JSON unmarshal error checks in
SheetBatchSetStyle.DryRunfor--data.
Comments suppressed due to low confidence (1)
shortcuts/sheets/lark_sheets_cell_style_and_merge.go:171
- DryRun functions must return *common.DryRunAPI, but this branch returns common.FlagErrorf (an error) on JSON parse failure, which will not compile. Validate already calls validateBatchStyleData and rejects invalid --data before dry-run runs, so either remove this error-return path or adjust the DryRun/runner API to allow returning an error.
if err := json.Unmarshal([]byte(runtime.Str("data")), &data); err != nil {
return common.FlagErrorf("--data must be valid JSON: %v", err)
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
9466ee5 to
890cf52
Compare
|
This PR does not compile. The Since // Safe to ignore: Validate already verified JSON validity
_ = json.Unmarshal([]byte(runtime.Str("style")), &style) |
Two DryRun functions in the sheets shortcuts called json.Unmarshal without checking the return value. This looks like a bug, but Validate already parses and validates the same --style / --data JSON before DryRun runs, so the error is structurally impossible at this point. Use _ = assignment + comment to silence the unchecked-error lint warning and make the safety invariant explicit to future readers.
890cf52 to
bb9bd12
Compare
|
@fangshuyu-768 Thanks for the detailed feedback. You were absolutely right — the original commit still had the I've amended the commit to use |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #935 +/- ##
=======================================
Coverage 65.92% 65.92%
=======================================
Files 523 523
Lines 49692 49692
=======================================
Hits 32758 32758
Misses 14134 14134
Partials 2800 2800 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
🚀 PR Preview Install Guide🧰 CLI updatenpm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@bb9bd12bd365670cbb90ddc7298ffdb1aa5afb3e🧩 Skill updatenpx skills add KhanCold/cli#fix/dryrun-missing-json-error-handling -y -g |
…larksuite#935) Two DryRun functions in the sheets shortcuts called json.Unmarshal without checking the return value. This looks like a bug, but Validate already parses and validates the same --style / --data JSON before DryRun runs, so the error is structurally impossible at this point. Use _ = assignment + comment to silence the unchecked-error lint warning and make the safety invariant explicit to future readers. Co-authored-by: KhanCold <KhanCold@users.noreply.github.com>
Summary
Two DryRun functions in the sheets shortcuts called
json.Unmarshalwithout checking the return value. This looks like a bug, butValidatealready parses and validates the same--style/--dataJSON beforeDryRunruns, so the error is structurally impossible at this point.Use
_ =assignment + comment to silence the unchecked-error lint warning and make the safety invariant explicit to future readers.Changes
SheetSetStyle.DryRun: document whyjson.Unmarshalof--stylecan be safely ignoredSheetBatchSetStyle.DryRun: document whyjson.Unmarshalof--datacan be safely ignored (viavalidateBatchStyleData())Note
The initial attempt added
if err != nil { return common.FlagErrorf(...) }insideDryRun, butDryRunmust return*common.DryRunAPI(noterror), so that would not compile. The correct fix is to acknowledge the already-validated invariant instead.Summary by CodeRabbit