Coverage for paintmaskanimator/errors.py: 100%

4 statements  

« prev     ^ index     » next       coverage.py v7.17.0, created at 2026-11-02 04:50 +0000

1"""Application exception types and the shared catch tuple for user actions. 

2 

3Top-level user-action handlers (open/save/import/export/…) must turn *expected* 

4failures into a message box, and must **not** swallow programmer errors. 

5``AttributeError``/``TypeError``/``KeyError``/``IndexError`` are deliberately 

6absent from :data:`OPERATION_ERRORS`: they signal a defect in this code base, and 

7catching them turned real bugs into a generic "操作に失敗しました" dialog that 

8neither the test suite nor CI could ever see. 

9 

10When an operation needs to abort with a message meant for the user, raise 

11:class:`OperationError` rather than a bare ``ValueError``/``RuntimeError`` -- 

12that makes the intent explicit and keeps the catch tuple honest. 

13""" 

14import zipfile 

15 

16 

17class PaintMaskAnimatorError(Exception): 

18 """Base class for every exception this application raises on purpose.""" 

19 

20 

21class OperationError(PaintMaskAnimatorError): 

22 """A user action failed for an expected reason; ``str(exc)`` is shown as-is.""" 

23 

24 

25# Expected failures for the top-level user-action handlers: our own deliberate 

26# aborts, file I/O, out-of-memory on large canvases, and the malformed-data / 

27# unsupported-backend signals raised by PIL, numpy, psd_tools and Qt. 

28OPERATION_ERRORS = ( 

29 OperationError, 

30 OSError, 

31 MemoryError, 

32 ValueError, # PIL/numpy/psd_tools: malformed or unsupported input data 

33 RuntimeError, # PIL/Qt: unavailable codec or backend 

34 zipfile.BadZipFile, # archive read/write paths (projects, PSD) — not an OSError 

35)