github/copilot-sdk · error · ValueError

Missing required field 'message' in StopError

Error message

Missing required field 'message' in StopError

What it means

StopError.from_dict requires the 'message' key in the stop-error payload; when absent it raises ValueError. The library treats 'message' as the mandatory human-readable error text and refuses to construct a StopError without it.

Solutions

  1. Update/align the server or event producer to include 'message' in StopError payloads
  2. Remap the payload in an adapter: if 'message' missing, derive it from 'error'/'detail' before calling from_dict
  3. Fix mocks in tests to include {'message': ...}

Example fix

// before
StopError.from_dict({"error": "session stopped"})
// after
payload = {"error": "session stopped"}
StopError.from_dict({"message": payload.get("message") or payload["error"]})
Defensive patterns

Strategy: type-guard

Validate before calling

def has_stop_error_message(obj) -> bool:
    return isinstance(obj, dict) and obj.get("message") is not None

Type guard

def is_stop_error_payload(obj: object) -> bool:
    return isinstance(obj, dict) and isinstance(obj.get("message"), str)

Try / catch

try:
    err = StopError.from_dict(payload)
except ValueError as e:
    if "Missing required field 'message'" in str(e):
        err = StopError(str(payload.get("error", payload)))
    else:
        raise

Prevention

When it happens

Trigger: A stop/error event from the server arrives as a dict without a 'message' field, e.g. {'code': 500} or {'error': '...'} shape instead of the expected flat {'message': '...'} shape.

Common situations: Server emitting a differently shaped error object after an upgrade; test fakes returning partial payloads; relaying an underlying error object directly instead of mapping it to the expected schema.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of github/copilot-sdk@cd8cf15dc3 (2026-09-09). Data as JSON: /api/errors/b50786b4a989225c. Report an issue: GitHub.

Appendix: source

Thrown at python/copilot/client.py:882

        result["protocolVersion"] = self.protocol_version
        return result


@dataclass
class StopError(Exception):
    """Error that occurred during client stop cleanup."""

    message: str  # Error message describing what failed during cleanup

    def __post_init__(self) -> None:
        Exception.__init__(self, self.message)

    @staticmethod
    def from_dict(obj: Any) -> StopError:
        assert isinstance(obj, dict)
        message = obj.get("message")
        if message is None:
            raise ValueError("Missing required field 'message' in StopError")
        return StopError(str(message))

    def to_dict(self) -> dict:
        result: dict = {}
        result["message"] = self.message
        return result


@dataclass
class GetStatusResponse:
    """Response from status.get"""

    version: str  # Package version (e.g., "1.0.0")
    protocol_version: int  # Protocol version for SDK compatibility

    @staticmethod
    def from_dict(obj: Any) -> GetStatusResponse:
        assert isinstance(obj, dict)

View on GitHub (pinned to cd8cf15dc3)