File: exceptions.py

package info (click to toggle)
siril 1.4.0~rc2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 47,352 kB
  • sloc: ansic: 174,082; cpp: 28,254; python: 7,891; makefile: 974; xml: 777; sh: 271
file content (141 lines) | stat: -rw-r--r-- 4,767 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# Copyright (C) 2005-2011 Francois Meyer (dulle at free.fr)
# Copyright (C) 2012-2025 team free-astro (see more in AUTHORS file)
# Reference site is https://siril.org
# SPDX-License-Identifier: GPL-3.0-or-later

"""
Exceptions submodule for Siril, providing exception classes for use
in exception raising within the sirilpy module.
"""

from .translations import _
from .enums import CommandStatus

class SirilError(Exception):
    """
    Base exception class for all Siril-related errors.

    All other Siril exceptions inherit from this class, making it easy
    to catch any Siril-related error with a single except clause.

    """
    def __init__(self, message: str = _("An error occurred")):
        self.message = message
        super().__init__(self.message)

class SirilConnectionError(SirilError):
    """
    Raised when there are problems connecting to or
    communicating with Siril.
    This includes cases like:

    - Siril not running

    - Socket connection failures

    - Communication protocol errors

    - Unexpected disconnections

    SirilConnectionError is not raised directly but will be wrapped in
    a SirilError. It should generally be regarded as fatal and the
    script should shut down gracefully if possible or just stop.
    """

    def __init__(self, message: str = _("Failed to connect to Siril")):
        super().__init__(message)

class SharedMemoryError(SirilError):
    """
    Raised when there are problems connecting to or
    communicating with Siril using shared memory.

    SharedMemoryError is not raised directly but will be wrapped in
    a SirilError. It should generally be regarded as fatal and the
    script should shut down gracefully if possible or just stop.
    """

    def __init__(self, message: str = _("Siril shared memory error")):
        super().__init__(message)

class CommandError(SirilError):
    """
    Raised when a command sent to Siril fails to execute properly.
    (Note: 'command' in this case refers to internal commands sent
    from the python module to the Siril python handler, not Siril
    commands of the type that might be entered in the Siril command
    entry.) The full set of command status codes is shown in the
    CommandStatus enum. These exceptions are often recoverable and
    should therefore be handled before generically handling other
    SirilError types that are considered fatal.

    Attributes:
        status_code: (CommandStatus) Indicates the status code returned
                     by the Siril command. This may be used in error
                     handlers to allow scripts to handle some types of
                     command error and continue (e.g. by prompting
                     a user intervention).
    """

    def __init__(self, message: str = _("Command execution failed"),
                 status_code=CommandStatus.CMD_GENERIC_ERROR):
        super().__init__(message)
        self.status_code = status_code

class DataError(SirilError):
    """
    Raised when there are problems with data handling.
    This includes cases like:

    - Invalid image data

    - Data conversion errors

    - Memory allocation failures

    - Buffer overflows
    """
    def __init__(self, message: str = _("Error handling data")):
        super().__init__(message)

class NoImageError(SirilError):
    """
    Raised when a method requires an image to be loaded
    but no image is loaded. These exceptions are often recoverable and
    should therefore be handled before generically handling other
    SirilError types that are considered fatal.
    """
    def __init__(self, message: str = _("No Siril image loaded")):
        super().__init__(message)

class NoSequenceError(SirilError):
    """
    Raised when a method requires a sequence to be loaded
    but no sequence is loaded. These exceptions are often recoverable
    and should therefore be handled before generically handling other
    SirilError types that are considered fatal.
    """
    def __init__(self, message: str = _("No Siril sequence loaded")):
        super().__init__(message)

class ProcessingThreadBusyError(SirilError):
    """
    Exception raised when the processing thread is already in use.
    """
    def __init__(self, message: str = _("Siril processing thread is busy")):
        super().__init__(message)

class ImageDialogOpenError(SirilError):
    """
    Exception raised when an image processing dialog is open.
    """
    def __init__(self, message: str = _("Siril image dialog is open")):
        super().__init__(message)

class MouseModeError(SirilError):
    """
    Exception raised when Siril is in the wrong mouse mode.
    """
    def __init__(self, message: str = _("Siril mouse mode error")):
        super().__init__(message)