fix(ocr): narrow exception handling and add unit tests for ensure_blla_model

- _model_is_loadable: narrow bare except to (RuntimeError, OSError, ValueError)
  with DEBUG-level fallback for unexpected exceptions — prevents silent masking
  of missing kraken install or AttributeError on vgsl
- _run_segtrain: replace bare except:pass with log.warning so height-check
  fallback is visible in container logs
- New test_ensure_blla_model.py: covers model-OK early return, incompatible
  model rename+replace, and missing model download paths

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-04-14 15:24:04 +02:00
parent 9b6b6f4f7e
commit fdae60a528
3 changed files with 75 additions and 3 deletions

View File

@@ -33,9 +33,12 @@ def _model_is_loadable(path: str) -> bool:
vgsl.TorchVGSLModel.load_model(path)
return True
except Exception as e:
except (RuntimeError, OSError, ValueError) as e:
log.warning("Model at %s failed to load: %s", path, e)
return False
except Exception:
log.debug("Unexpected error loading model at %s", path, exc_info=True)
return False
def _download_blla() -> str: