Structured error returned from canvas handlers. .. note:: **Experimental.** This type is part of an experimental wire-protocol surface and may change or be removed in future SDK or CLI releases.
| 105 | |
| 106 | |
| 107 | class CanvasError(Exception): |
| 108 | """Structured error returned from canvas handlers. |
| 109 | |
| 110 | .. note:: |
| 111 | |
| 112 | **Experimental.** This type is part of an experimental wire-protocol |
| 113 | surface and may change or be removed in future SDK or CLI releases. |
| 114 | """ |
| 115 | |
| 116 | def __init__(self, code: str, message: str) -> None: |
| 117 | self.code = code |
| 118 | self.message = message |
| 119 | super().__init__(f"{code}: {message}") |
| 120 | |
| 121 | def to_envelope(self) -> dict[str, str]: |
| 122 | return {"code": self.code, "message": self.message} |
| 123 | |
| 124 | @classmethod |
| 125 | def no_handler(cls) -> CanvasError: |
| 126 | """Default error returned when a custom action has no handler.""" |
| 127 | return cls( |
| 128 | "canvas_action_no_handler", |
| 129 | "No handler implemented for this canvas action", |
| 130 | ) |
| 131 | |
| 132 | @classmethod |
| 133 | def handler_unset(cls) -> CanvasError: |
| 134 | """Error returned when a canvas RPC arrives but no handler is installed.""" |
| 135 | return cls( |
| 136 | "canvas_handler_unset", |
| 137 | "No CanvasHandler installed on this session; " |
| 138 | "install one via SessionConfig.canvas_handler before creating the session.", |
| 139 | ) |
| 140 | |
| 141 | |
| 142 | class CanvasHandler(ABC): |
no outgoing calls
searching dependent graphs…