Source code for scfile.exceptions

from dataclasses import dataclass
from typing import Optional


[docs] class ScFileException(Exception): """Base exception for scfile library.""" ...
[docs] class DecodingError(ScFileException): """Base exception occurring while file decoding.""" ...
[docs] class EncodingError(ScFileException): """Base exception occurring while file encoding.""" ...
[docs] class ParsingError(ScFileException): """Base exception occurring due to unexpected file structure.""" ...
[docs] class UnsupportedError(ScFileException): """Base exception occurring intentionally for unsupported formats.""" ...
[docs] class BaseIOError(ScFileException): """Base exception occurring i/o operations.""" @property def prefix(self) -> str: return "File" def __str__(self): return f"{self.prefix}"
[docs] @dataclass class FileError(BaseIOError): """Base exception occurring file i/o operations.""" location: str def __str__(self): return f"{super().__str__()} {self.location}"
[docs] @dataclass class FileNotFound(FileError): """Raised when file doesn't exist.""" def __str__(self): return f"{super().__str__()} not found or doesn't exist."
[docs] @dataclass class EmptyFileError(FileError): """Raised when file is empty.""" def __str__(self): return f"{super().__str__()} is empty."
[docs] @dataclass class UnsupportedFormatError(FileError): """Raised when file format (by suffix) is not supported.""" suffix: str def __str__(self): return f"{super().__str__()} has unsupported suffix '{self.suffix}'."
[docs] @dataclass class InvalidSignatureError(FileError): """Raised when file signature doesn't match expected.""" actual: bytes expected: bytes def __str__(self): return ( f"{super().__str__()} has invalid signature - " f"'{self.actual.hex().upper()}' != '{self.expected.hex().upper()}'. " "(file suffix doesn't match file content)." )
[docs] @dataclass class InvalidStructureError(FileError): """Raised when file structure is invalid.""" position: Optional[int] = None def __str__(self): return f"{super().__str__()} parsing failed{f' at position {self.position}' if self.position else ''}."
[docs] class RegionError(ScFileException): """Base exception for region operations.""" pass
[docs] @dataclass class RegionFileError(RegionError): """Raised when a region file fails to decode.""" path: str def __str__(self): return f"Region '{self.path}'"
[docs] class MergeInterrupted(RegionError): """Raised when region merge is interrupted by user.""" def __str__(self): return "Merge interrupted"