mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-28 18:02:38 +02:00
Add error code for unexpected errors in conversion
This commit is contained in:
parent
8e4f04a52e
commit
94f569cdf5
3 changed files with 13 additions and 4 deletions
|
@ -373,9 +373,9 @@ async def main() -> int:
|
|||
error_code = 0 # Success!
|
||||
except errors.ConversionException as e: # Expected Errors
|
||||
error_code = e.error_code
|
||||
except (RuntimeError, TimeoutError, ValueError) as e: # Unexpected Errors
|
||||
except Exception as e:
|
||||
converter.update_progress(str(e), error=True)
|
||||
error_code = 1
|
||||
error_code = errors.UnexpectedConversionError.error_code
|
||||
if not running_on_qubes():
|
||||
# Write debug information (containers version)
|
||||
with open("/tmp/dangerzone/captured_output.txt", "wb") as container_log:
|
||||
|
|
|
@ -72,9 +72,12 @@ async def main() -> None:
|
|||
converter = DocumentToPixels()
|
||||
await converter.convert()
|
||||
except errors.ConversionException as e:
|
||||
await write_bytes(str(e).encode(), file=sys.stderr)
|
||||
sys.exit(e.error_code)
|
||||
except (RuntimeError, TimeoutError, ValueError) as e:
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
await write_bytes(str(e).encode(), file=sys.stderr)
|
||||
error_code = errors.UnexpectedConversionError.error_code
|
||||
sys.exit(error_code)
|
||||
|
||||
num_pages = len(list(out_dir.glob("*.rgb")))
|
||||
await write_int(num_pages)
|
||||
|
|
|
@ -3,6 +3,7 @@ from typing import List, Optional, Type
|
|||
# XXX: errors start at 128 for conversion-related issues
|
||||
ERROR_SHIFT = 128
|
||||
|
||||
|
||||
class ConversionException(Exception):
|
||||
error_message = "Unspecified error"
|
||||
error_code = ERROR_SHIFT
|
||||
|
@ -67,6 +68,11 @@ class PDFtoPPMInvalidDepth(PDFtoPPMException):
|
|||
error_message = "Error converting PDF to Pixels (Invalid PPM depth)"
|
||||
|
||||
|
||||
class UnexpectedConversionError(PDFtoPPMException):
|
||||
error_code = ERROR_SHIFT + 100
|
||||
error_message = "Some unxpected error occured while converting the document"
|
||||
|
||||
|
||||
def exception_from_error_code(error_code: int) -> Optional[ConversionException]:
|
||||
"""returns the conversion exception corresponding to the error code"""
|
||||
for cls in ConversionException.get_subclasses():
|
||||
|
|
Loading…
Reference in a new issue