Skip to content

Commit 887575a

Browse files
authored
Updated the python errorStatusHandler to escalate details from IndexError and NotImplementedError and made ImageSequenceReference provide a more helpful exception message when trying to get a frame url from a zero rate or zero duration instance. (#783)
1 parent f294caf commit 887575a

File tree

3 files changed

+62
-4
lines changed

3 files changed

+62
-4
lines changed

src/opentimelineio/imageSequenceReference.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,15 @@ ImageSequenceReference::ImageSequenceReference(std::string const& target_url_bas
6969

7070
std::string
7171
ImageSequenceReference::target_url_for_image_number(int const image_number, ErrorStatus* error_status) const {
72-
if (image_number >= this->number_of_images_in_sequence()) {
72+
if (_rate == 0) {
73+
*error_status = ErrorStatus(ErrorStatus::ILLEGAL_INDEX, "Zero rate sequence has no frames.");
74+
return std::string();
75+
}
76+
else if (!this->available_range().has_value() || this->available_range().value().duration().value() == 0) {
77+
*error_status = ErrorStatus(ErrorStatus::ILLEGAL_INDEX, "Zero duration sequences has no frames.");
78+
return std::string();
79+
}
80+
else if (image_number >= this->number_of_images_in_sequence()) {
7381
*error_status = ErrorStatus(ErrorStatus::ILLEGAL_INDEX);
7482
return std::string();
7583
}

src/py-opentimelineio/opentimelineio-bindings/otio_errorStatusHandler.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ ErrorStatusHandler::~ErrorStatusHandler() noexcept(false) {
2828
if (!error_status) {
2929
return;
3030
}
31-
31+
3232
switch(error_status.outcome) {
3333
case ErrorStatus::NOT_IMPLEMENTED:
34-
throw py::not_implemented_error();
34+
throw py::not_implemented_error(error_status.details);
3535
case ErrorStatus::ILLEGAL_INDEX:
36-
throw py::index_error();
36+
throw py::index_error(error_status.details);
3737
case ErrorStatus::KEY_NOT_FOUND:
3838
throw py::key_error(error_status.details);
3939
case ErrorStatus::INTERNAL_ERROR:

tests/test_image_sequence_reference.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,3 +611,53 @@ def test_negative_frame_numbers(self):
611611
ref.target_url_for_image_number(i),
612612
"file:///show/seq/shot/rndr/show_shot.{:04}.exr".format(i - 1),
613613
)
614+
615+
def test_target_url_for_image_number_with_missing_timing_info(self):
616+
ref = otio.schema.ImageSequenceReference(
617+
"file:///show/seq/shot/rndr/",
618+
"show_shot.",
619+
".exr",
620+
frame_zero_padding=4,
621+
start_frame=1,
622+
frame_step=1,
623+
rate=24,
624+
)
625+
626+
# Make sure the right error and a useful message raised when
627+
# source_range is either un-set or zero duration.
628+
with self.assertRaises(IndexError) as exception_manager:
629+
ref.target_url_for_image_number(0)
630+
631+
self.assertEqual(
632+
str(exception_manager.exception),
633+
"Zero duration sequences has no frames.",
634+
)
635+
636+
ref.available_range = otio.opentime.TimeRange(
637+
otio.opentime.RationalTime(12, 24),
638+
otio.opentime.RationalTime(0, 1),
639+
)
640+
641+
with self.assertRaises(IndexError) as exception_manager:
642+
ref.target_url_for_image_number(0)
643+
644+
self.assertEqual(
645+
str(exception_manager.exception),
646+
"Zero duration sequences has no frames.",
647+
)
648+
649+
# Set the duration and make sure a similarly useful message comes
650+
# when rate is un-set.
651+
ref.available_range = otio.opentime.TimeRange(
652+
otio.opentime.RationalTime(12, 24),
653+
otio.opentime.RationalTime(48, 24),
654+
)
655+
ref.rate = 0
656+
657+
with self.assertRaises(IndexError) as exception_manager:
658+
ref.target_url_for_image_number(0)
659+
660+
self.assertEqual(
661+
str(exception_manager.exception),
662+
"Zero rate sequence has no frames.",
663+
)

0 commit comments

Comments
 (0)