Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error Handling #141

Open
manthey opened this issue Jul 25, 2023 · 2 comments
Open

Error Handling #141

manthey opened this issue Jul 25, 2023 · 2 comments

Comments

@manthey
Copy link
Contributor

manthey commented Jul 25, 2023

Running on a few files on windows, the server stops due to an exception:

  + Exception Group Traceback (most recent call last):
  |   File "imagedephi\__main__.py", line 4, in <module>
  |   File "click\core.py", line 1130, in __call__
  |   File "click\core.py", line 1055, in main
  |   File "imagedephi\utils\cli.py", line 48, in invoke
  |   File "click\core.py", line 1657, in invoke
  |   File "click\core.py", line 1404, in invoke
  |   File "click\core.py", line 760, in invoke
  |   File "imagedephi\utils\cli.py", line 17, in wrapper
  |   File "asyncio\runners.py", line 190, in run
  |   File "asyncio\runners.py", line 118, in run
  |   File "asyncio\base_events.py", line 653, in run_until_complete
  |   File "imagedephi\main.py", line 108, in gui
  |   File "asyncio\taskgroups.py", line 147, in __aexit__
  | ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)
  +-+---------------- 1 ----------------
    | Traceback (most recent call last):
    |   File "starlette\routing.py", line 677, in lifespan
    |   File "contextlib.py", line 211, in __aexit__
    |   File "imagedephi\gui.py", line 35, in lifespan
    |   File "hypercorn\asyncio\task_group.py", line 23, in _handle
    |   File "hypercorn\app_wrappers.py", line 33, in __call__
    |   File "fastapi\applications.py", line 289, in __call__
    |   File "starlette\applications.py", line 122, in __call__
    |   File "starlette\middleware\errors.py", line 184, in __call__
    |   File "starlette\middleware\errors.py", line 162, in __call__
    |   File "starlette\middleware\exceptions.py", line 79, in __call__
    |   File "starlette\middleware\exceptions.py", line 68, in __call__
    |   File "fastapi\middleware\asyncexitstack.py", line 20, in __call__
    |   File "fastapi\middleware\asyncexitstack.py", line 17, in __call__
    |   File "starlette\routing.py", line 718, in __call__
    |   File "starlette\routing.py", line 276, in handle
    |   File "starlette\routing.py", line 66, in app
    |   File "fastapi\routing.py", line 273, in app
    |   File "fastapi\routing.py", line 192, in run_endpoint_function
    |   File "starlette\concurrency.py", line 41, in run_in_threadpool
    |   File "anyio\to_thread.py", line 33, in run_sync
    |   File "anyio\_backends\_asyncio.py", line 877, in run_sync_in_worker_thread
    |   File "anyio\_backends\_asyncio.py", line 807, in run
    |   File "imagedephi\gui.py", line 122, in redact
    |   File "imagedephi\redact\redact.py", line 77, in redact_images
    |   File "imagedephi\redact\redact.py", line 106, in show_redaction_plan
    |   File "imagedephi\redact\build_redaction_plan.py", line 32, in build_redaction_plan
    |   File "imagedephi\redact\svs.py", line 84, in __init__
    |   File "imagedephi\redact\tiff.py", line 133, in __init__
    |   File "imagedephi\redact\svs.py", line 115, in get_associated_image_key_for_ifd
    | KeyError: 270
    | 
    | During handling of the above exception, another exception occurred:
    | 
    | Traceback (most recent call last):
    |   File "hypercorn\asyncio\__init__.py", line 49, in serve
    |   File "hypercorn\asyncio\run.py", line 173, in worker_serve
    |   File "hypercorn\asyncio\lifespan.py", line 43, in handle_lifespan
    |   File "hypercorn\app_wrappers.py", line 33, in __call__
    |   File "fastapi\applications.py", line 289, in __call__
    |   File "starlette\applications.py", line 122, in __call__
    |   File "starlette\middleware\errors.py", line 149, in __call__
    |   File "starlette\middleware\exceptions.py", line 55, in __call__
    |   File "fastapi\middleware\asyncexitstack.py", line 20, in __call__
    |   File "fastapi\middleware\asyncexitstack.py", line 17, in __call__
    |   File "starlette\routing.py", line 707, in __call__
    |   File "starlette\routing.py", line 690, in lifespan
    |   File "hypercorn\asyncio\lifespan.py", line 104, in asgi_send
    | hypercorn.utils.LifespanFailureError: Lifespan failure in shutdown. 'Traceback (most recent call last):
  File "starlette\routing.py", line 677, in lifespan
  File "contextlib.py", line 211, in __aexit__
  File "imagedephi\gui.py", line 35, in lifespan
  File "hypercorn\asyncio\task_group.py", line 23, in _handle
  File "hypercorn\app_wrappers.py", line 33, in __call__
  File "fastapi\applications.py", line 289, in __call__
  File "starlette\applications.py", line 122, in __call__
  File "starlette\middleware\errors.py", line 184, in __call__
  File "starlette\middleware\errors.py", line 162, in __call__
  File "starlette\middleware\exceptions.py", line 79, in __call__
  File "starlette\middleware\exceptions.py", line 68, in __call__
  File "fastapi\middleware\asyncexitstack.py", line 20, in __call__
  File "fastapi\middleware\asyncexitstack.py", line 17, in __call__
  File "starlette\routing.py", line 718, in __call__
  File "starlette\routing.py", line 276, in handle
  File "starlette\routing.py", line 66, in app
  File "fastapi\routing.py", line 273, in app
  File "fastapi\routing.py", line 192, in run_endpoint_function
  File "starlette\concurrency.py", line 41, in run_in_threadpool
  File "anyio\to_thread.py", line 33, in run_sync
  File "anyio\_backends\_asyncio.py", line 877, in run_sync_in_worker_thread
  File "anyio\_backends\_asyncio.py", line 807, in run
  File "imagedephi\gui.py", line 122, in redact
  File "imagedephi\redact\redact.py", line 77, in redact_images
  File "imagedephi\redact\redact.py", line 106, in show_redaction_plan
  File "imagedephi\redact\build_redaction_plan.py", line 32, in build_redaction_plan
  File "imagedephi\redact\svs.py", line 84, in __init__
  File "imagedephi\redact\tiff.py", line 133, in __init__
  File "imagedephi\redact\svs.py", line 115, in get_associated_image_key_for_ifd
KeyError: 270
'
    +------------------------------------
[12480] Failed to execute script '__main__' due to unhandled exception!

We should catch (and log) exceptions rather than halting the program.

@naglepuff
Copy link
Collaborator

Do you recall what file this happened to? I'm trying to figure out a root cause.

Is it valid for an svs file to have IFDs with no ImageDescription? I think that this line of code should only be hit if we determine that a given image is an svs file. Maybe our method of relying on file extension has caught up with us?

@manthey
Copy link
Contributor Author

manthey commented Aug 8, 2023

Yes, it appears to be a valid svs file (at least according to a version of ImageScope). If I run tifftools dump on the file, I get the text below. I can provide a synthetic test file or the original (the synthetic file just runs the ttdump_to_tiff.py program on the dump below). It looks like the macro and label images within the svs don't have ImageDescriptions (but the pyramidal images do).

-- /mnt/transfer/nomacrodescription.svs --
Header: 0x4949 <little-endian> <BigTIFF>
Directory 0: offset 625945748 (0x254f2c94)
  NewSubfileType 254 (0xFE) LONG: 0
  ImageWidth 256 (0x100) SHORT: 57201
  ImageLength 257 (0x101) LONG: 93897
  BitsPerSample 258 (0x102) SHORT: <3> 8 8 8
  Compression 259 (0x103) SHORT: 7 (JPEG 7 (0x7))
  Photometric 262 (0x106) SHORT: 6 (YCbCr 6 (0x6))
  ImageDescription 270 (0x10E) ASCII: Aperio Leica Biosystems Segue v1.0 
57201x93897 [0,0,57201x93897] (256x256) JPEG/YCC Q=91|AppMag = 40|Gamma = 2.2|Left = 0|MPP = 0.263158|ScanScope ID = alpha5|StripeWidth = 4096|Top = 0
  SamplesPerPixel 277 (0x115) SHORT: 3
  PlanarConfig 284 (0x11C) SHORT: 1 (Chunky 1 (0x1))
  TileWidth 322 (0x142) SHORT: 256
  TileLength 323 (0x143) SHORT: 256
  TileOffsets 324 (0x144) LONG8: <82208> 16 2208671 4352655 6444943 8483123 10470627 12442988 14401228 16353995 18295573 20235202 22189119 24178011 26193868 28259835 30387541 32587950 34896332 37149521 39366259 ...
  TileByteCounts 325 (0x145) LONG8: <82208> 6153 5892 5911 5636 5518 5409 5374 5392 5403 5323 5371 5469 5488 5416 5601 5772 6026 5811 5681 5562 ...
  ImageDepth 32997 (0x80E5) LONG: 1
  ICCProfile 34675 (0x8773) UNDEFINED: <13113264> b'\x00\xc8\x17\xb0SICC\x04\x00\x00\x00scnrRGB ' ...
Directory 1: offset 640401894 (0x262bc1e6)
  NewSubfileType 254 (0xFE) LONG: 0
  ImageWidth 256 (0x100) SHORT: 467
  ImageLength 257 (0x101) SHORT: 768
  BitsPerSample 258 (0x102) SHORT: <3> 8 8 8
  Compression 259 (0x103) SHORT: 7 (JPEG 7 (0x7))
  Photometric 262 (0x106) SHORT: 6 (YCbCr 6 (0x6))
  ImageDescription 270 (0x10E) ASCII: Aperio Leica Biosystems Segue v1.0 
467x768 [0,0,467x768] (467x768) JPEG/YCC Q=100|CompressedFile = \\uscavs-eng-is1.aperio.int\is1\Images\alpha5\dfd77469-ba7f-8d82-e768-42efc297d999.svs|Left = 0|MPP = 32.233179|ScanScope ID = alpha5|Top = 0
  StripOffsets 273 (0x111) LONG8: 640374844
  SamplesPerPixel 277 (0x115) SHORT: 3
  RowsPerStrip 278 (0x116) SHORT: 768
  StripByteCounts 279 (0x117) LONG8: 27049
  PlanarConfig 284 (0x11C) SHORT: 1 (Chunky 1 (0x1))
Directory 2: offset 669891302 (0x27edbae6)
  NewSubfileType 254 (0xFE) LONG: 0
  ImageWidth 256 (0x100) SHORT: 14300
  ImageLength 257 (0x101) SHORT: 23474
  BitsPerSample 258 (0x102) SHORT: <3> 8 8 8
  Compression 259 (0x103) SHORT: 7 (JPEG 7 (0x7))
  Photometric 262 (0x106) SHORT: 6 (YCbCr 6 (0x6))
  ImageDescription 270 (0x10E) ASCII: Aperio Leica Biosystems Segue v1.0 
14300x23474 [0,0,14300x23474] (256x256) JPEG/YCC Q=91|AppMag = 10|Gamma = 2.2|Left = 0|MPP = 1.052632|ScanScope ID = alpha5|StripeWidth = 4096|Top = 0
  SamplesPerPixel 277 (0x115) SHORT: 3
  PlanarConfig 284 (0x11C) SHORT: 1 (Chunky 1 (0x1))
  TileWidth 322 (0x142) SHORT: 256
  TileLength 323 (0x143) SHORT: 256
  TileOffsets 324 (0x144) LONG8: <5152> 640402392 640404973 640407102 640409130 640411238 640413365 640415388 640417368 640419455 640421704 640423829 640425920 640428133 640430307 640432472 640434529 640436640 640438765 640440862 640442951 ...
  TileByteCounts 325 (0x145) LONG8: <5152> 2581 2129 2028 2108 2127 2023 1980 2087 2249 2125 2091 2213 2174 2165 2057 2111 2125 2097 2089 2166 ...
  ICCProfile 34675 (0x8773) UNDEFINED: <13113264> b'\x00\xc8\x17\xb0SICC\x04\x00\x00\x00scnrRGB ' ...
Directory 3: offset 684883546 (0x28d27e5a)
  NewSubfileType 254 (0xFE) LONG: 0
  ImageWidth 256 (0x100) SHORT: 3575
  ImageLength 257 (0x101) SHORT: 5868
  BitsPerSample 258 (0x102) SHORT: <3> 8 8 8
  Compression 259 (0x103) SHORT: 7 (JPEG 7 (0x7))
  Photometric 262 (0x106) SHORT: 6 (YCbCr 6 (0x6))
  ImageDescription 270 (0x10E) ASCII: Aperio Leica Biosystems Segue v1.0 
3575x5868 [0,0,3575x5868] (256x256) JPEG/YCC Q=91|AppMag = 2.5|Gamma = 2.2|Left = 0|MPP = 4.210526|ScanScope ID = alpha5|StripeWidth = 4096|Top = 0
  SamplesPerPixel 277 (0x115) SHORT: 3
  PlanarConfig 284 (0x11C) SHORT: 1 (Chunky 1 (0x1))
  TileWidth 322 (0x142) SHORT: 256
  TileLength 323 (0x143) SHORT: 256
  TileOffsets 324 (0x144) LONG8: <322> 683087482 683089738 683091634 683093492 683095365 683097201 683099205 683101577 683103661 683106972 683111427 683113871 683116130 683118448 683120601 683122735 683124645 683126642 683128644 683130622 ...
  TileByteCounts 325 (0x145) LONG8: <322> 2256 1896 1858 1873 1836 2004 2372 2084 3311 4455 2444 2259 2318 2153 2134 1910 1997 2002 1978 1852 ...
  ICCProfile 34675 (0x8773) UNDEFINED: <13113264> b'\x00\xc8\x17\xb0SICC\x04\x00\x00\x00scnrRGB ' ...
Directory 4: offset 704373032 (0x29fbe128)
  NewSubfileType 254 (0xFE) LONG: 1 (ReducedImage 1 (0x1))
  ImageWidth 256 (0x100) SHORT: 1961
  ImageLength 257 (0x101) SHORT: 1601
  BitsPerSample 258 (0x102) SHORT: <3> 8 8 8
  Compression 259 (0x103) SHORT: 5 (LZW 5 (0x5))
  Photometric 262 (0x106) SHORT: 2 (RGB 2 (0x2))
  StripOffsets 273 (0x111) LONG8: 698002442
  SamplesPerPixel 277 (0x115) SHORT: 3
  RowsPerStrip 278 (0x116) SHORT: 1601
  StripByteCounts 279 (0x117) LONG8: 6370589
  PlanarConfig 284 (0x11C) SHORT: 1 (Chunky 1 (0x1))
  Predictor 317 (0x13D) SHORT: 2 (Horizontal 2 (0x2))
Directory 5: offset 705278412 (0x2a09b1cc)
  NewSubfileType 254 (0xFE) LONG: 9 (ReducedImage 1 (0x1), Macro 8 (0x8))
  ImageWidth 256 (0x100) SHORT: 1831
  ImageLength 257 (0x101) SHORT: 4201
  BitsPerSample 258 (0x102) SHORT: <3> 8 8 8
  Compression 259 (0x103) SHORT: 7 (JPEG 7 (0x7))
  Photometric 262 (0x106) SHORT: 2 (RGB 2 (0x2))
  StripOffsets 273 (0x111) LONG8: 704373288
  SamplesPerPixel 277 (0x115) SHORT: 3
  RowsPerStrip 278 (0x116) SHORT: 4201
  StripByteCounts 279 (0x117) LONG8: 905124
  PlanarConfig 284 (0x11C) SHORT: 1 (Chunky 1 (0x1))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants