Skip to content

Improve error messages for agent-friendly recovery and help guidance #31

@bigdra50

Description

@bigdra50

概要

コーディングエージェントがエラーメッセージから適切に次のアクションを決定できるよう、エラーメッセージの改善を行う。

現状の分析で以下の課題を特定した。

課題

1. リカバリ手順の欠如

エラーメッセージに「次に何をすべきか」が含まれていない箇所がある。

レイヤー エラー箇所 現状メッセージ 不足情報
Unity Playmode.cs pause/unpause/step Cannot pause: not in play mode Play Mode に入るコマンドの示唆
Relay INSTANCE_NOT_FOUND Instance not found: {id} 接続中インスタンス一覧の確認方法
Relay AMBIGUOUS_INSTANCE Ambiguous instance 'X': matches A, B --instance での絞り込み方法
Relay インスタンス0台 Instance not found after waiting... Unity 側の接続確認手順

※ 良い例(既存): ConnectionErrorPlease ensure the relay server is running: $ python -m relay.server --port 6500
※ 良い例(既存): Tests.cs → Cannot start tests while Editor is in Play Mode. Stop Play Mode first.
※ 良い例(#29): Screenshot.cs → GameView screenshot requires Play Mode. Enter Play Mode first with 'manage_editor play' command.

2. Valid values 列挙の不統一

Playmode.cs の HandleCommand だけ Valid actions: が欠落している。

// 現状 (Playmode.cs)
$"Unknown action: {action}"

// 他の全ツール
$"Unknown action: {action}. Valid actions: enter, exit, pause, unpause, step, state"

3. CLI オプション不足時の help 誘導

CLI 側でオプション不足時のメッセージに --help への誘導がない。

# 現状
Error: --name or --id required

# 改善案
Error: --name or --id required. Run 'u gameobject find --help' for usage.

対象箇所(app.py 内の print_error + raise typer.Exit(1)):

  • gameobject find/modify/active/delete: --name or --id required
  • component list/inspect/add/modify/remove: --target or --target-id required
  • asset prefab: --source or --source-id required
  • scene load: --path or --name required
  • uitree inspect: ref argument or --panel + --name required

4. instance 指定ミスの防止

シナリオ 現状 改善案
--instance でパス間違い Instance not found: {id} 接続中インスタンス一覧を表示
複数インスタンス一致 Ambiguous instance 'X': matches A, B u instances または --instance <full-path> を示唆
インスタンス0台 Instance not found after waiting... Ensure Unity Editor has UnityBridge connected. Check with 'u instances'.

5. 必須パラメータメッセージの不統一(低優先度)

Unity 側でフォーマットに揺れがある:

  • 'path' is required
  • 'type' parameter is required
  • 'name' parameter is required for create action
  • Either 'target' (name) or 'targetId' (instanceID) is required

統一フォーマットの検討: '{param}' is required または Either '{a}' or '{b}' is required

対象ファイル

  • UnityBridge/Editor/Tools/Playmode.cs — Valid actions 追加、リカバリ手順追加
  • relay/server.py — INSTANCE_NOT_FOUND / AMBIGUOUS_INSTANCE メッセージ改善
  • relay/instance_registry.py — AmbiguousInstanceError メッセージ改善
  • unity_cli/cli/app.py — help 誘導の追加、instance エラー時のガイダンス

優先度

  1. リカバリ手順の追加(エージェントへの影響大)
  2. instance 指定ミス防止
  3. help 誘導
  4. Valid values 統一
  5. メッセージフォーマット統一

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions