Skip to content

Commit 8de0741

Browse files
committed
applied new SDK that fixes error handling in cli.py
1 parent 6245223 commit 8de0741

3 files changed

Lines changed: 26 additions & 8 deletions

File tree

Containerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Use the same base image version as the clams-python python library version
2-
FROM ghcr.io/clamsproject/clams-python-ffmpeg-hf:1.7.2
2+
FROM ghcr.io/clamsproject/clams-python-ffmpeg-hf:1.7.3
33
# See https://github.com/orgs/clamsproject/packages?tab=packages&q=clams-python for more base images
44
# IF you want to automatically publish this image to the clamsproject organization,
55
# 1. you should have generated this template without --no-github-actions flag

cli.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@
66
"""
77

88
import argparse
9+
import json
910
import sys
1011
from contextlib import redirect_stdout
1112

13+
import jsonschema
14+
1215
import app
1316

1417
import clams.app
1518
from clams import AppMetadata
19+
from clams.envelop import EnvelopeError
1620

1721

1822
def metadata_to_argparser(app_metadata: AppMetadata) -> argparse.ArgumentParser:
@@ -81,11 +85,24 @@ def metadata_to_argparser(app_metadata: AppMetadata) -> argparse.ArgumentParser:
8185
params[pname] = pvalue
8286
else:
8387
params[pname] = [pvalue]
84-
if args.OUT_MMIF_FILE.name == '<stdout>':
85-
with redirect_stdout(sys.stderr):
88+
# Mirror the HTTP server's error handling (see clams.restify): an invalid
89+
# input is reported and exits non-zero, while an app-level failure is
90+
# recorded as an error view instead of crashing with a raw traceback.
91+
try:
92+
if args.OUT_MMIF_FILE.name == '<stdout>':
93+
with redirect_stdout(sys.stderr):
94+
out_mmif = clamsapp.annotate(in_data, **params)
95+
else:
8696
out_mmif = clamsapp.annotate(in_data, **params)
87-
else:
88-
out_mmif = clamsapp.annotate(in_data, **params)
97+
except (jsonschema.exceptions.ValidationError, json.JSONDecodeError, EnvelopeError) as e:
98+
detail = e.message if isinstance(e, jsonschema.exceptions.ValidationError) else str(e)
99+
print(f"Invalid input data. See below for validation error.\n\n{detail}", file=sys.stderr)
100+
sys.exit(1)
101+
except Exception:
102+
clamsapp.logger.exception("Error in annotation")
103+
out_mmif = clamsapp.record_error(in_data, **params).serialize(pretty=True)
104+
args.OUT_MMIF_FILE.write(out_mmif)
105+
sys.exit(1)
89106
args.OUT_MMIF_FILE.write(out_mmif)
90107
else:
91108
arg_parser.print_help()

requirements.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Make sure clams-python version is explicitly specified, at least the lower bound
2-
clams-python==1.7.2
3-
# mmif-python[cv] transitively provides PyAV, Pillow, ffmpeg-python, wurlitzer
4-
# (the modern post-cv2 vdh stack). The visualize/ scripts use PyAV directly.
2+
clams-python==1.7.3
3+
# mmif-python[cv] pulls the video I/O deps: PyAV, Pillow, ffmpeg-python,
4+
# wurlitzer, and opencv-python. This app uses only the PyAV/PTS-based vdh
5+
# path, but the [cv] extra still bundles opencv-python regardless.
56
mmif-python[cv]
67
torch==2.*
78
torchvision

0 commit comments

Comments
 (0)