Skip to content

fix: Invalid tool parameters now return a readable error result instead of an RPC failure - #1522

Merged
hatayama merged 2 commits into
v3-betafrom
refactor/c3-validation-errors-as-responses
Jul 5, 2026
Merged

hatayama merged 2 commits into
v3-betafrom
refactor/c3-validation-errors-as-responses

Conversation

@hatayama

@hatayama hatayama commented Jul 5, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Invalid tool parameters (unknown action values, empty pause-point ids, non-positive timeouts, unsupported test filter types) now come back as a normal result with Success=false and a clear message, instead of a generic RPC error

User Impact

  • Before: passing an invalid parameter to record-input, replay-input, simulate-keyboard, simulate-mouse-ui, run-tests, or the pause-point tools surfaced as "UNITY_RPC_ERROR" on stderr with exit code 1, hiding the actual problem
  • After: the tool returns Success=false with a message naming the invalid value (e.g. "Unknown keyboard action: 999"), readable directly from the result JSON

Changes

  • Converted user-input validation throws to Success=false responses across the affected use cases; contract guards for null parameters remain exceptions
  • TestFilterCreationService and the mouse UI command factory now return (value, errorMessage) tuples instead of throwing on out-of-range enum values
  • PausePointResponse gains a Success field (defaults to true), matching the other tool responses
  • Added tests covering each converted validation path

Verification

  • dist/darwin-arm64/uloop compile: 0 errors / 0 warnings
  • dist/darwin-arm64/uloop run-tests (regex over the affected suites): 88 passed / 0 failed

Review in cubic

User-input validation errors (out-of-range action enums, invalid
pause-point ids and timeouts, unsupported test filter types) were
thrown as exceptions, reaching the CLI as generic JSON-RPC errors on
stderr with exit code 1. Convert them to Success=false responses so
they arrive as normal tool results the caller can read. Contract
guards for null parameters stay as exceptions.
@coderabbitai

coderabbitai Bot commented Jul 5, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 0fd6d169-b28c-4cca-b002-fdd97fe4d6f6

📥 Commits

Reviewing files that changed from the base of the PR and between 52c77c0 and e3995da.

📒 Files selected for processing (2)
  • Packages/src/Editor/FirstPartyTools/PausePoint/PausePointTools.cs
  • Packages/src/Editor/FirstPartyTools/SimulateMouseUi/SimulateMouseUiUseCase.cs
🚧 Files skipped from review as they are similar to previous changes (2)
  • Packages/src/Editor/FirstPartyTools/PausePoint/PausePointTools.cs
  • Packages/src/Editor/FirstPartyTools/SimulateMouseUi/SimulateMouseUiUseCase.cs

📝 Walkthrough

Walkthrough

Several editor tool use cases now return validation-style failure responses for invalid or unsupported input instead of throwing exceptions, and the affected tests were updated or added to assert the new behavior.

Changes

Validation failure refactor

Layer / File(s) Summary
PausePoint validation returns failure responses
Packages/src/Editor/FirstPartyTools/PausePoint/PausePointTools.cs, Assets/Tests/Editor/PausePointTests.cs
PausePointResponse.Success defaults to true; Enable and Clear now validate ids and timeout values by returning failure responses, and tests cover empty ids and zero timeout.
RecordInput and ReplayInput unknown action handling
Packages/src/Editor/FirstPartyTools/RecordInput/RecordInputUseCase.cs, Packages/src/Editor/FirstPartyTools/ReplayInput/ReplayInputUseCase.cs, Assets/Tests/Editor/InputActionValidationTests.cs
Default switch branches return failure results with unknown-action messages and action strings, and tests assert invalid enum values produce validation failures.
RunTests filter creation via TryCreateFilter
Packages/src/Editor/FirstPartyTools/RunTests/TestFilterCreationService.cs, Packages/src/Editor/FirstPartyTools/RunTests/RunTestsUseCase.cs, Assets/Tests/Editor/RunTestsToolTests.cs, Assets/Tests/Editor/RunTestsUseCaseTests.cs
CreateFilter is replaced by TryCreateFilter returning a filter and error string; RunTestsUseCase.ExecuteAsync returns a failure response on error, and tests assert tuple-based results and unsupported-filter validation.
SimulateKeyboard and SimulateMouseUi unknown action handling
Packages/src/Editor/FirstPartyTools/SimulateKeyboard/SimulateKeyboardUseCase.cs, Packages/src/Editor/FirstPartyTools/SimulateMouseUi/SimulateMouseUiUseCase.cs, Assets/Tests/Editor/SimulateMouseUiActionValidationTests.cs
SimulateKeyboard returns a failure response for unknown actions; SimulateMouseUi switches to TryFromSchema and TryConvertMouseAction, returns failure responses on conversion or execution failures, and a new test covers invalid mouse UI actions.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant RunTestsUseCase
  participant TestFilterCreationService
  participant RunTestsUseCaseTests
  RunTestsUseCase->>TestFilterCreationService: TryCreateFilter(filterType, filterValue)
  TestFilterCreationService-->>RunTestsUseCase: (filter, errorMessage)
  alt errorMessage present
    RunTestsUseCase-->>RunTestsUseCaseTests: Response(Success=false, Message)
  else filter created
    RunTestsUseCase-->>RunTestsUseCaseTests: Continue execution with filter
  end
Loading
sequenceDiagram
  participant SimulateMouseUiActionValidationTests
  participant SimulateMouseUiUseCase
  participant MouseUiSimulationCommand
  SimulateMouseUiActionValidationTests->>SimulateMouseUiUseCase: ExecuteAsync(invalid action)
  SimulateMouseUiUseCase->>MouseUiSimulationCommand: TryFromSchema(schema)
  MouseUiSimulationCommand-->>SimulateMouseUiUseCase: (null, errorMessage)
  SimulateMouseUiUseCase-->>SimulateMouseUiActionValidationTests: Response(Success=false, Action)
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: invalid tool parameters now return readable failure results instead of RPC failures.
Description check ✅ Passed The description clearly matches the changeset and describes the validation-to-result behavior changes and added tests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ 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 refactor/c3-validation-errors-as-responses

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
Packages/src/Editor/FirstPartyTools/SimulateMouseUi/SimulateMouseUiUseCase.cs (1)

224-231: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Reuse CreateFailure for the defensive default case.

This branch duplicates the exact shape already built by CreateFailure(parameters, message) (Line 155). Reusing it keeps failure-response construction consistent.

♻️ Proposed refactor
                 default:
                     // Unreachable when TryFromSchema succeeds; kept as a defensive Success=false response
                     // instead of a throw so any future MouseAction addition surfaces as a validation failure.
-                    return new SimulateMouseUiResponse
-                    {
-                        Success = false,
-                        Message = $"Unknown mouse action: {parameters.Action}",
-                        Action = parameters.Action.ToString()
-                    };
+                    return CreateFailure(parameters, $"Unknown mouse action: {parameters.Action}");
🤖 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
`@Packages/src/Editor/FirstPartyTools/SimulateMouseUi/SimulateMouseUiUseCase.cs`
around lines 224 - 231, The defensive default branch in SimulateMouseUiUseCase
should reuse the existing CreateFailure(parameters, message) helper instead of
manually constructing a SimulateMouseUiResponse with the same failure shape.
Update the unreachable fallback in the SimulateMouseUiUseCase logic to call
CreateFailure with the unknown-action message so response construction stays
consistent with the other failure paths.
🤖 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
`@Packages/src/Editor/FirstPartyTools/SimulateMouseUi/SimulateMouseUiUseCase.cs`:
- Around line 224-231: The defensive default branch in SimulateMouseUiUseCase
should reuse the existing CreateFailure(parameters, message) helper instead of
manually constructing a SimulateMouseUiResponse with the same failure shape.
Update the unreachable fallback in the SimulateMouseUiUseCase logic to call
CreateFailure with the unknown-action message so response construction stays
consistent with the other failure paths.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 66bc19b9-9b1a-45e1-9ec5-ae22baa695ed

📥 Commits

Reviewing files that changed from the base of the PR and between 138ad9e and 52c77c0.

⛔ Files ignored due to path filters (2)
  • Assets/Tests/Editor/InputActionValidationTests.cs.meta is excluded by none and included by none
  • Assets/Tests/Editor/SimulateMouseUiActionValidationTests.cs.meta is excluded by none and included by none
📒 Files selected for processing (12)
  • Assets/Tests/Editor/InputActionValidationTests.cs
  • Assets/Tests/Editor/PausePointTests.cs
  • Assets/Tests/Editor/RunTestsToolTests.cs
  • Assets/Tests/Editor/RunTestsUseCaseTests.cs
  • Assets/Tests/Editor/SimulateMouseUiActionValidationTests.cs
  • Packages/src/Editor/FirstPartyTools/PausePoint/PausePointTools.cs
  • Packages/src/Editor/FirstPartyTools/RecordInput/RecordInputUseCase.cs
  • Packages/src/Editor/FirstPartyTools/ReplayInput/ReplayInputUseCase.cs
  • Packages/src/Editor/FirstPartyTools/RunTests/RunTestsUseCase.cs
  • Packages/src/Editor/FirstPartyTools/RunTests/TestFilterCreationService.cs
  • Packages/src/Editor/FirstPartyTools/SimulateKeyboard/SimulateKeyboardUseCase.cs
  • Packages/src/Editor/FirstPartyTools/SimulateMouseUi/SimulateMouseUiUseCase.cs

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 14 files

Re-trigger cubic

Route the unknown-mouse-action branch through the existing
CreateFailure helper, assert TryFromSchema's error contract instead
of masking it with a fallback message, return only the error from
pause-point id validation, and use a nullable enum for the mouse
action conversion so the invalid state is unrepresentable.
@hatayama
hatayama merged commit 2aff8bd into v3-beta Jul 5, 2026
10 checks passed
@hatayama
hatayama deleted the refactor/c3-validation-errors-as-responses branch July 5, 2026 15:28
@github-actions github-actions Bot mentioned this pull request Jul 11, 2026
RyanXie123 pushed a commit to RyanXie123/unity-cli-loop that referenced this pull request Sep 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant