Exceptions

abb_rws_client_python_rw6.core.exceptions

Custom exceptions for abb_rws_client_python_rw6.

Author: Clement RACINET

Exception hierarchy::

RWSError                   ← base class, always catchable with a single except
├── RWSConnectionError     ← unreachable network / TCP timeout
├── RWSTimeoutError        ← HTTP timeout exceeded
├── RWSAuthenticationError ← persistent 401 after digest handshake
├── RWSHTTPError           ← any HTTP response >= 400 not covered above
│   └── RWSNotFoundError   ← 404 (variable / resource not found)
├── MastershipError        ← base class for mastership errors
│   ├── MastershipDenied   ← controller refuses mastership acquisition
│   └── MastershipNotHeld  ← write attempt without an active mastership
└── RWSValueError          ← invalid RAPID value / serialization failure
CTRL_CODES

Complete dictionary of ABB RobotWare 6 return codes. Source: robot_controller_return_code.xml (RWS API documentation). Key : integer code (positive = success, negative = error) Value: ABB symbolic name (e.g. "SYS_CTRL_E_MASTER_REJECT")

MastershipDenied

Bases: MastershipError

The controller refused the mastership acquisition request.

Typical causes:

  • The RAPID program is running in automatic mode.
  • Another client already holds mastership.
  • The UAS denies access for this user.

ABB constraint: SYS_CTRL_E_MASTER_REJECT (code -1073445859).

Example
>>> try:
...     await client.post("rw/mastership", params={"action": "request"})
... except MastershipDenied:
...     print("Mastership denied by controller")
Source code in abb_rws_client_python_rw6/core/exceptions.py
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
class MastershipDenied(MastershipError):
    """The controller refused the mastership acquisition request.

    Typical causes:

    - The RAPID program is running in automatic mode.
    - Another client already holds mastership.
    - The UAS denies access for this user.

    ABB constraint: ``SYS_CTRL_E_MASTER_REJECT`` (code ``-1073445859``).

    Example:
        ```python
        >>> try:
        ...     await client.post("rw/mastership", params={"action": "request"})
        ... except MastershipDenied:
        ...     print("Mastership denied by controller")
        ```
    """

    def __init__(self, message: str = "Mastership request denied by controller") -> None:
        super().__init__(message, status_code=None)

MastershipError

Bases: RWSError

Base class for RAPID mastership-related errors.

Example
>>> try:
...     await client.post("rw/mastership", params={"action": "request"})
... except MastershipError:
...     print("Mastership operation failed")
Source code in abb_rws_client_python_rw6/core/exceptions.py
427
428
429
430
431
432
433
434
435
436
437
class MastershipError(RWSError):
    """Base class for RAPID mastership-related errors.

    Example:
        ```python
        >>> try:
        ...     await client.post("rw/mastership", params={"action": "request"})
        ... except MastershipError:
        ...     print("Mastership operation failed")
        ```
    """

MastershipNotHeld

Bases: MastershipError

Write operation attempted without an active mastership.

Raised client-side before the HTTP request is even sent, as a guard against out-of-order calls.

Example
>>> try:
...     await set_rapid_variable(client, ...)
... except MastershipNotHeld:
...     print("Acquire mastership first")
Source code in abb_rws_client_python_rw6/core/exceptions.py
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
class MastershipNotHeld(MastershipError):
    """Write operation attempted without an active mastership.

    Raised client-side before the HTTP request is even sent,
    as a guard against out-of-order calls.

    Example:
        ```python
        >>> try:
        ...     await set_rapid_variable(client, ...)
        ... except MastershipNotHeld:
        ...     print("Acquire mastership first")
        ```
    """

    def __init__(self) -> None:
        super().__init__("Cannot write: mastership is not currently held")

RWSAuthenticationError

Bases: RWSError

Digest authentication refused (persistent HTTP 401).

Indicates incorrect credentials or a user not authorised in the controller's UAS (User Authorization System).

Example
>>> try:
...     await client.get("rw/rapid/execution")
... except RWSAuthenticationError:
...     print("Invalid credentials")
Source code in abb_rws_client_python_rw6/core/exceptions.py
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
class RWSAuthenticationError(RWSError):
    """Digest authentication refused (persistent HTTP 401).

    Indicates incorrect credentials or a user not authorised in the
    controller's UAS (User Authorization System).

    Example:
        ```python
        >>> try:
        ...     await client.get("rw/rapid/execution")
        ... except RWSAuthenticationError:
        ...     print("Invalid credentials")
        ```
    """

    def __init__(self, message: str = "Authentication failed (HTTP 401)") -> None:
        super().__init__(message, status_code=401)

RWSConnectionError

Bases: RWSError

Cannot establish a TCP connection to the controller.

Raised when httpx.ConnectError or httpx.ConnectTimeout is caught after all retries have been exhausted.

Example
>>> try:
...     await client.get("rw/rapid/execution")
... except RWSConnectionError:
...     print("Controller unreachable")
Source code in abb_rws_client_python_rw6/core/exceptions.py
298
299
300
301
302
303
304
305
306
307
308
309
310
311
class RWSConnectionError(RWSError):
    """Cannot establish a TCP connection to the controller.

    Raised when ``httpx.ConnectError`` or ``httpx.ConnectTimeout`` is caught
    after all retries have been exhausted.

    Example:
        ```python
        >>> try:
        ...     await client.get("rw/rapid/execution")
        ... except RWSConnectionError:
        ...     print("Controller unreachable")
        ```
    """

RWSError

Bases: Exception

Base class for all RWS errors.

All exceptions raised by this library inherit from RWSError, allowing callers to catch every library error with a single except RWSError clause.

Attributes:
  • message (str) –

    Human-readable error description.

  • status_code (int | None) –

    Associated HTTP status code, if applicable.

Example
>>> try:
...     await client.get("rw/rapid/execution")
... except RWSError as exc:
...     print(exc.message)
Source code in abb_rws_client_python_rw6/core/exceptions.py
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
class RWSError(Exception):
    """Base class for all RWS errors.

    All exceptions raised by this library inherit from ``RWSError``,
    allowing callers to catch every library error with a single
    ``except RWSError`` clause.

    Attributes:
        message: Human-readable error description.
        status_code: Associated HTTP status code, if applicable.

    Example:
        ```python
        >>> try:
        ...     await client.get("rw/rapid/execution")
        ... except RWSError as exc:
        ...     print(exc.message)
        ```
    """

    message: str
    status_code: int | None

    def __init__(self, message: str, status_code: int | None = None) -> None:
        super().__init__(message)
        self.message = message
        self.status_code = status_code

    def __repr__(self) -> str:
        if self.status_code is not None:
            return (
                f"{self.__class__.__name__}("
                f"message={self.message!r}, "
                f"status_code={self.status_code})"
            )
        return f"{self.__class__.__name__}(message={self.message!r})"

RWSHTTPError

Bases: RWSError

Unexpected HTTP response (>= 400) not covered by a more specific exception.

Attributes:
  • ctrl_code (int | None) –

    ABB return code extracted from the response body, if present.

  • ctrl_code_name (str | None) –

    ABB symbolic name for the code (e.g. "SYS_CTRL_E_EXEC_STATE").

Example
>>> try:
...     await client.post("rw/rapid/execution", params={"action": "start"})
... except RWSHTTPError as exc:
...     print(exc.ctrl_code_name)
Source code in abb_rws_client_python_rw6/core/exceptions.py
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
class RWSHTTPError(RWSError):
    """Unexpected HTTP response (>= 400) not covered by a more specific exception.

    Attributes:
        ctrl_code: ABB return code extracted from the response body, if present.
        ctrl_code_name: ABB symbolic name for the code
            (e.g. ``"SYS_CTRL_E_EXEC_STATE"``).

    Example:
        ```python
        >>> try:
        ...     await client.post("rw/rapid/execution", params={"action": "start"})
        ... except RWSHTTPError as exc:
        ...     print(exc.ctrl_code_name)
        ```
    """

    ctrl_code: int | None
    ctrl_code_name: str | None

    def __init__(
        self,
        message: str,
        status_code: int | None = None,
        ctrl_code: int | None = None,
    ) -> None:
        super().__init__(message, status_code=status_code)
        self.ctrl_code = ctrl_code
        self.ctrl_code_name = ctrl_code_name(ctrl_code) if ctrl_code is not None else None

    def __repr__(self) -> str:
        parts = [f"message={self.message!r}"]
        if self.status_code is not None:
            parts.append(f"status_code={self.status_code}")
        if self.ctrl_code is not None:
            parts.append(f"ctrl_code={self.ctrl_code_name!r}")
        return f"{self.__class__.__name__}({', '.join(parts)})"

RWSNotFoundError

Bases: RWSHTTPError

RWS resource not found (HTTP 404).

Typically raised for a non-existent RAPID variable, incorrect module name, or unknown task.

Attributes:
  • resource (str) –

    Path of the resource that was not found.

Example
>>> try:
...     await client.get("rw/rapid/symbol/data/RAPID/T_ROB1/MOD/MISSING")
... except RWSNotFoundError as exc:
...     print(exc.resource)
Source code in abb_rws_client_python_rw6/core/exceptions.py
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
class RWSNotFoundError(RWSHTTPError):
    """RWS resource not found (HTTP 404).

    Typically raised for a non-existent RAPID variable, incorrect module
    name, or unknown task.

    Attributes:
        resource: Path of the resource that was not found.

    Example:
        ```python
        >>> try:
        ...     await client.get("rw/rapid/symbol/data/RAPID/T_ROB1/MOD/MISSING")
        ... except RWSNotFoundError as exc:
        ...     print(exc.resource)
        ```
    """

    resource: str

    def __init__(self, resource: str, ctrl_code: int | None = None) -> None:
        super().__init__(
            f"Resource not found: {resource}",
            status_code=404,
            ctrl_code=ctrl_code,
        )
        self.resource = resource

RWSTimeoutError

Bases: RWSError

The controller did not respond within the configured timeout.

Raised when httpx.ReadTimeout or httpx.PoolTimeout is caught after all retries have been exhausted.

Example
>>> try:
...     await client.get("rw/rapid/execution")
... except RWSTimeoutError:
...     print("Request timed out")
Source code in abb_rws_client_python_rw6/core/exceptions.py
314
315
316
317
318
319
320
321
322
323
324
325
326
327
class RWSTimeoutError(RWSError):
    """The controller did not respond within the configured timeout.

    Raised when ``httpx.ReadTimeout`` or ``httpx.PoolTimeout`` is caught
    after all retries have been exhausted.

    Example:
        ```python
        >>> try:
        ...     await client.get("rw/rapid/execution")
        ... except RWSTimeoutError:
        ...     print("Request timed out")
        ```
    """

RWSValueError

Bases: RWSError

Invalid RAPID value or serialization / deserialization failure.

Raised by core/serializers.py when a Python value cannot be converted to RWS format, or conversely when a raw RWS string cannot be parsed into a Python type.

Example
>>> try:
...     rws_to_robtarget("not_a_valid_robtarget")
... except RWSValueError as exc:
...     print(exc.message)
Source code in abb_rws_client_python_rw6/core/exceptions.py
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
class RWSValueError(RWSError):
    """Invalid RAPID value or serialization / deserialization failure.

    Raised by ``core/serializers.py`` when a Python value cannot be
    converted to RWS format, or conversely when a raw RWS string cannot
    be parsed into a Python type.

    Example:
        ```python
        >>> try:
        ...     rws_to_robtarget("not_a_valid_robtarget")
        ... except RWSValueError as exc:
        ...     print(exc.message)
        ```
    """

ctrl_code_name(code)

Return the ABB symbolic name for a return code, or its decimal representation.

Parameters:
  • code (int) –

    Integer code returned by the ABB controller.

Returns:
  • str –

    Symbolic name (e.g. "SYS_CTRL_E_MASTER_REJECT") or

  • str –

    "UNKNOWN(code)" if the code is not registered.

Example
>>> ctrl_code_name(-1073445859)
'SYS_CTRL_E_MASTER_REJECT'
>>> ctrl_code_name(0)
'UNKNOWN(0)'
Source code in abb_rws_client_python_rw6/core/exceptions.py
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
def ctrl_code_name(code: int) -> str:
    """Return the ABB symbolic name for a return code, or its decimal representation.

    Args:
        code: Integer code returned by the ABB controller.

    Returns:
        Symbolic name (e.g. ``"SYS_CTRL_E_MASTER_REJECT"``) or
        ``"UNKNOWN(code)"`` if the code is not registered.

    Example:
        ```python
        >>> ctrl_code_name(-1073445859)
        'SYS_CTRL_E_MASTER_REJECT'
        >>> ctrl_code_name(0)
        'UNKNOWN(0)'
        ```
    """
    return CTRL_CODES.get(code, f"UNKNOWN({code})")