Skip to content

Commit cdf969d

Browse files
authored
Use exceptions instead of ErrorStatus (#12)
* Use exceptions instead of ErrorStatus in opentime * Implement exceptions corresponding to OTIO ErrorStatus * Use exception instead of error status in tests * Remove ErrorStatus * Remove ErrorStatus import statement * Verbose output in github actions * Fix test on windows * Replace plain Exception with OpentimeException, inline function to throw Exception from JNI layer * Use DeserializationException for KEY_NOT_FOUND/INTERNAL_ERROR error, and set less verbose gradle output
1 parent 607c610 commit cdf969d

File tree

100 files changed

+1790
-2254
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+1790
-2254
lines changed

src/main/cpp/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ add_library(jotio SHARED
22
io_opentimeline_OTIOFinalizer.cpp
33
class_codes.cpp
44
utilities.cpp
5-
io_opentimeline_opentime_ErrorStatus.cpp
5+
exceptions.cpp
66
io_opentimeline_OTIONative.cpp
77
io_opentimeline_opentime_RationalTime.cpp
88
io_opentimeline_opentime_TimeRange.cpp
@@ -12,7 +12,6 @@ add_library(jotio SHARED
1212
io_opentimeline_opentimelineio_AnyDictionary_Iterator.cpp
1313
io_opentimeline_opentimelineio_AnyVector.cpp
1414
io_opentimeline_opentimelineio_AnyVector_Iterator.cpp
15-
io_opentimeline_opentimelineio_ErrorStatus.cpp
1615
io_opentimeline_opentimelineio_SerializableObject.cpp
1716
io_opentimeline_opentimelineio_SerializableObjectWithMetadata.cpp
1817
io_opentimeline_opentimelineio_SerializableCollection.cpp

src/main/cpp/exceptions.cpp

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
#include "exceptions.h"
2+
#include "utilities.h"
3+
4+
inline jint throwJavaException(JNIEnv *env, const char *className, std::string &msg) {
5+
jclass exClass = env->FindClass(className);
6+
return env->ThrowNew(exClass, msg.c_str());
7+
}
8+
9+
jint processOpenTimeErrorStatus(JNIEnv *env, opentime::ErrorStatus &errorStatus) {
10+
switch (errorStatus.outcome) {
11+
case opentime::ErrorStatus::Outcome::INVALID_TIMECODE_RATE:
12+
return throwJavaException(env, "io/opentimeline/opentime/exception/InvalidTimecodeRateException",
13+
errorStatus.details);
14+
case opentime::ErrorStatus::Outcome::INVALID_TIMECODE_STRING:
15+
return throwJavaException(env, "io/opentimeline/opentime/exception/InvalidTimecodeStringException",
16+
errorStatus.details);
17+
case opentime::ErrorStatus::Outcome::INVALID_TIME_STRING:
18+
return throwJavaException(env, "io/opentimeline/opentime/exception/InvalidTimestringException",
19+
errorStatus.details);
20+
case opentime::ErrorStatus::Outcome::INVALID_RATE_FOR_DROP_FRAME_TIMECODE:
21+
return throwJavaException(env,
22+
"io/opentimeline/opentime/exception/InvalidRateForDropFrameTimecodeException",
23+
errorStatus.details);
24+
case opentime::ErrorStatus::Outcome::NON_DROPFRAME_RATE:
25+
return throwJavaException(env, "io/opentimeline/opentime/exception/NonDropframeRateException",
26+
errorStatus.details);
27+
case opentime::ErrorStatus::Outcome::TIMECODE_RATE_MISMATCH:
28+
return throwJavaException(env, "io/opentimeline/opentime/exception/TimecodeRateMismatchException",
29+
errorStatus.details);
30+
case opentime::ErrorStatus::Outcome::NEGATIVE_VALUE: {
31+
return throwJavaException(env, "io/opentimeline/opentime/exception/NegativeValueException",
32+
errorStatus.details);
33+
}
34+
case opentime::ErrorStatus::Outcome::OK:
35+
return 0;
36+
default: {
37+
return throwJavaException(env, "io/opentimeline/opentime/exception/OpentimeException",
38+
errorStatus.details);
39+
}
40+
}
41+
}
42+
43+
jint processOTIOErrorStatus(JNIEnv *env, OTIO_NS::ErrorStatus &errorStatus) {
44+
switch (errorStatus.outcome) {
45+
case OTIO_NS::ErrorStatus::Outcome::NOT_IMPLEMENTED: {
46+
return throwJavaException(env, "java/lang/UnsupportedOperationException",
47+
errorStatus.full_description);
48+
}
49+
case OTIO_NS::ErrorStatus::Outcome::TYPE_MISMATCH: {
50+
return throwJavaException(env, "io/opentimeline/opentimelineio/exception/TypeMismatchException",
51+
errorStatus.full_description);
52+
}
53+
case OTIO_NS::ErrorStatus::Outcome::FILE_OPEN_FAILED:
54+
case OTIO_NS::ErrorStatus::Outcome::FILE_WRITE_FAILED: {
55+
return throwJavaException(env, "java/io/IOException",
56+
errorStatus.full_description);
57+
}
58+
case OTIO_NS::ErrorStatus::Outcome::INTERNAL_ERROR:
59+
case OTIO_NS::ErrorStatus::Outcome::KEY_NOT_FOUND: {
60+
return throwJavaException(env, "io/opentimeline/opentimelineio/exception/DeserializationException",
61+
errorStatus.full_description);
62+
}
63+
case OTIO_NS::ErrorStatus::Outcome::ILLEGAL_INDEX: {
64+
return throwJavaException(env, "java/lang/IndexOutOfBoundsException",
65+
errorStatus.full_description);
66+
}
67+
case OTIO_NS::ErrorStatus::Outcome::MALFORMED_SCHEMA: {
68+
return throwJavaException(env,
69+
"io/opentimeline/opentimelineio/exception/MalformedSchemaException",
70+
errorStatus.full_description);
71+
}
72+
case OTIO_NS::ErrorStatus::Outcome::JSON_PARSE_ERROR: {
73+
return throwJavaException(env, "io/opentimeline/opentimelineio/exception/JSONParseException",
74+
errorStatus.full_description);
75+
}
76+
case OTIO_NS::ErrorStatus::Outcome::CANNOT_COMPUTE_AVAILABLE_RANGE: {
77+
return throwJavaException(env,
78+
"io/opentimeline/opentimelineio/exception/CannotComputeAvailableRangeException",
79+
errorStatus.full_description);
80+
}
81+
case OTIO_NS::ErrorStatus::Outcome::INVALID_TIME_RANGE: {
82+
return throwJavaException(env,
83+
"io/opentimeline/opentimelineio/exception/InvalidTimeRangeException",
84+
errorStatus.full_description);
85+
}
86+
case OTIO_NS::ErrorStatus::Outcome::OBJECT_WITHOUT_DURATION: {
87+
const char *className = "io/opentimeline/opentimelineio/exception/ObjectWithoutDurationException";
88+
jclass exClass = env->FindClass(className);
89+
jmethodID exceptionCtor = env->GetMethodID(exClass, "<init>",
90+
"(Ljava/lang/String;Lio/opentimeline/opentimelineio/SerializableObject;)V");
91+
jobject exObject = env->NewObject(exClass, exceptionCtor, errorStatus.details.c_str(),
92+
serializableObjectFromNative(env,
93+
const_cast<SerializableObject *>(errorStatus.object_details)));
94+
return env->Throw((jthrowable) exObject);
95+
}
96+
case OTIO_NS::ErrorStatus::Outcome::CANNOT_TRIM_TRANSITION: {
97+
return throwJavaException(env,
98+
"io/opentimeline/opentimelineio/exception/TransitionTrimException",
99+
errorStatus.full_description);
100+
}
101+
case OTIO_NS::ErrorStatus::Outcome::CHILD_ALREADY_PARENTED: {
102+
return throwJavaException(env,
103+
"io/opentimeline/opentimelineio/exception/ChildAlreadyParentedException",
104+
errorStatus.full_description);
105+
}
106+
case OTIO_NS::ErrorStatus::Outcome::NOT_A_CHILD_OF:
107+
case OTIO_NS::ErrorStatus::Outcome::NOT_A_CHILD:
108+
case OTIO_NS::ErrorStatus::Outcome::NOT_DESCENDED_FROM: {
109+
return throwJavaException(env,
110+
"io/opentimeline/opentimelineio/exception/NotAChildException",
111+
errorStatus.full_description);
112+
}
113+
case OTIO_NS::ErrorStatus::Outcome::OK:
114+
return 0;
115+
case OTIO_NS::ErrorStatus::Outcome::SCHEMA_ALREADY_REGISTERED:
116+
case OTIO_NS::ErrorStatus::Outcome::SCHEMA_NOT_REGISTERED:
117+
case OTIO_NS::ErrorStatus::Outcome::SCHEMA_VERSION_UNSUPPORTED:
118+
case OTIO_NS::ErrorStatus::Outcome::NOT_AN_ITEM:
119+
case OTIO_NS::ErrorStatus::Outcome::UNRESOLVED_OBJECT_REFERENCE:
120+
case OTIO_NS::ErrorStatus::Outcome::DUPLICATE_OBJECT_REFERENCE: {
121+
return throwJavaException(env,
122+
"io/opentimeline/opentimelineio/exception/OpenTimelineIOException",
123+
errorStatus.full_description);
124+
}
125+
default: {
126+
return throwJavaException(env,
127+
"io/opentimeline/opentimelineio/exception/OpenTimelineIOException",
128+
errorStatus.full_description);
129+
}
130+
}
131+
}

src/main/cpp/io_opentimeline_opentime_ErrorStatus.cpp

Lines changed: 0 additions & 48 deletions
This file was deleted.

src/main/cpp/io_opentimeline_opentime_RationalTime.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -177,19 +177,19 @@ Java_io_opentimeline_opentime_RationalTime_isValidTimecodeRate(
177177
/*
178178
* Class: io_opentimeline_opentime_RationalTime
179179
* Method: fromTimecode
180-
* Signature: (Ljava/lang/String;DLio/opentimeline/opentime/ErrorStatus;)Lio/opentimeline/opentime/RationalTime;
180+
* Signature: (Ljava/lang/String;D)Lio/opentimeline/opentime/RationalTime;
181181
*/
182182
JNIEXPORT jobject JNICALL Java_io_opentimeline_opentime_RationalTime_fromTimecode
183-
(JNIEnv *env, jclass thisClass, jstring timecode, jdouble rate, jobject errorStatusObj) {
184-
if (timecode == nullptr || errorStatusObj == nullptr) {
183+
(JNIEnv *env, jclass thisClass, jstring timecode, jdouble rate) {
184+
if (timecode == nullptr) {
185185
throwNullPointerException(env, "");
186186
return nullptr;
187187
}
188-
auto errorStatusHandle =
189-
getHandle<opentime::ErrorStatus>(env, errorStatusObj);
188+
auto errorStatus = opentime::ErrorStatus();
190189
std::string tc = env->GetStringUTFChars(timecode, 0);
191190
auto result =
192-
RationalTime::from_timecode(tc, rate, errorStatusHandle);
191+
RationalTime::from_timecode(tc, rate, &errorStatus);
192+
processOpenTimeErrorStatus(env, errorStatus);
193193
return rationalTimeToJObject(env, result);
194194
}
195195

@@ -199,16 +199,16 @@ JNIEXPORT jobject JNICALL Java_io_opentimeline_opentime_RationalTime_fromTimecod
199199
* Signature: (Ljava/lang/String;DLio/opentimeline/opentime/ErrorStatus;)Lio/opentimeline/opentime/RationalTime;
200200
*/
201201
JNIEXPORT jobject JNICALL Java_io_opentimeline_opentime_RationalTime_fromTimeString
202-
(JNIEnv *env, jclass thisClass, jstring timestring, jdouble rate, jobject errorStatusObj) {
203-
if (timestring == nullptr || errorStatusObj == nullptr) {
202+
(JNIEnv *env, jclass thisClass, jstring timestring, jdouble rate) {
203+
if (timestring == nullptr) {
204204
throwNullPointerException(env, "");
205205
return nullptr;
206206
}
207-
auto errorStatusHandle =
208-
getHandle<opentime::ErrorStatus>(env, errorStatusObj);
207+
auto errorStatus = opentime::ErrorStatus();
209208
std::string ts = env->GetStringUTFChars(timestring, 0);
210209
auto result =
211-
RationalTime::from_time_string(ts, rate, errorStatusHandle);
210+
RationalTime::from_time_string(ts, rate, &errorStatus);
211+
processOpenTimeErrorStatus(env, errorStatus);
212212
return rationalTimeToJObject(env, result);
213213
}
214214

@@ -218,16 +218,16 @@ JNIEXPORT jobject JNICALL Java_io_opentimeline_opentime_RationalTime_fromTimeStr
218218
* Signature: (Lio/opentimeline/opentime/RationalTime;DILio/opentimeline/opentime/ErrorStatus;)Ljava/lang/String;
219219
*/
220220
JNIEXPORT jstring JNICALL Java_io_opentimeline_opentime_RationalTime_toTimecodeNative
221-
(JNIEnv *env, jclass thisClass, jobject rtObj, jdouble rate, jint dropFrameIndex, jobject errorStatusObj) {
222-
if (rtObj == nullptr || errorStatusObj == nullptr) {
221+
(JNIEnv *env, jclass thisClass, jobject rtObj, jdouble rate, jint dropFrameIndex) {
222+
if (rtObj == nullptr) {
223223
throwNullPointerException(env, "");
224224
return nullptr;
225225
}
226-
auto errorStatusHandle =
227-
getHandle<opentime::ErrorStatus>(env, errorStatusObj);
226+
auto errorStatus = opentime::ErrorStatus();
228227
auto rt = rationalTimeFromJObject(env, rtObj);
229228
std::string tc = rt.to_timecode(
230-
rate, IsDropFrameRate(dropFrameIndex), errorStatusHandle);
229+
rate, IsDropFrameRate(dropFrameIndex), &errorStatus);
230+
processOpenTimeErrorStatus(env, errorStatus);
231231
return env->NewStringUTF(tc.c_str());
232232
}
233233

src/main/cpp/io_opentimeline_opentimelineio_Algorithms.cpp

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,60 +14,55 @@ using namespace opentimelineio::OPENTIMELINEIO_VERSION;
1414
/*
1515
* Class: io_opentimeline_opentimelineio_Algorithms
1616
* Method: flattenStack
17-
* Signature: (Lio/opentimeline/opentimelineio/Stack;Lio/opentimeline/opentimelineio/ErrorStatus;)Lio/opentimeline/opentimelineio/Track;
17+
* Signature: (Lio/opentimeline/opentimelineio/Stack;)Lio/opentimeline/opentimelineio/Track;
1818
*/
1919
JNIEXPORT jobject JNICALL Java_io_opentimeline_opentimelineio_Algorithms_flattenStack
20-
(JNIEnv *env, jobject thisObj, jobject inStack, jobject errorStatusObj) {
21-
if (inStack == nullptr || errorStatusObj == nullptr) {
20+
(JNIEnv *env, jobject thisObj, jobject inStack) {
21+
if (inStack == nullptr) {
2222
throwNullPointerException(env, "");
2323
return nullptr;
2424
}
25-
auto errorStatusHandle =
26-
getHandle<OTIO_NS::ErrorStatus>(env, errorStatusObj);
25+
auto errorStatus = OTIO_NS::ErrorStatus();
2726
auto inStackHandle =
2827
getHandle<SerializableObject::Retainer<OTIO_NS::Stack>>(env, inStack);
2928
auto stack = inStackHandle->value;
30-
auto result = OTIO_NS::flatten_stack(stack, errorStatusHandle);
29+
auto result = OTIO_NS::flatten_stack(stack, &errorStatus);
30+
processOTIOErrorStatus(env, errorStatus);
3131
return trackFromNative(env, result);
3232
}
3333

3434
/*
3535
* Class: io_opentimeline_opentimelineio_Algorithms
3636
* Method: flattenStackNative
37-
* Signature: ([Lio/opentimeline/opentimelineio/Track;Lio/opentimeline/opentimelineio/ErrorStatus;)Lio/opentimeline/opentimelineio/Track;
37+
* Signature: ([Lio/opentimeline/opentimelineio/Track;)Lio/opentimeline/opentimelineio/Track;
3838
*/
3939
JNIEXPORT jobject JNICALL Java_io_opentimeline_opentimelineio_Algorithms_flattenStackNative
40-
(JNIEnv *env, jobject thisObj, jobjectArray tracksArray, jobject errorStatusObj) {
41-
if (errorStatusObj == nullptr) {
42-
throwNullPointerException(env, "");
43-
return nullptr;
44-
}
45-
auto errorStatusHandle =
46-
getHandle<OTIO_NS::ErrorStatus>(env, errorStatusObj);
40+
(JNIEnv *env, jobject thisObj, jobjectArray tracksArray) {
41+
auto errorStatus = OTIO_NS::ErrorStatus();
4742
auto tracksVector = trackVectorFromArray(env, tracksArray);
48-
auto result = flatten_stack(tracksVector, errorStatusHandle);
43+
auto result = flatten_stack(tracksVector, &errorStatus);
44+
processOTIOErrorStatus(env, errorStatus);
4945
return trackFromNative(env, result);
5046
}
5147

5248
/*
5349
* Class: io_opentimeline_opentimelineio_Algorithms
5450
* Method: trackTrimmedToRange
55-
* Signature: (Lio/opentimeline/opentimelineio/Track;Lio/opentimeline/opentime/TimeRange;Lio/opentimeline/opentimelineio/ErrorStatus;)Lio/opentimeline/opentimelineio/Track;
51+
* Signature: (Lio/opentimeline/opentimelineio/Track;Lio/opentimeline/opentime/TimeRange;)Lio/opentimeline/opentimelineio/Track;
5652
*/
5753
JNIEXPORT jobject JNICALL Java_io_opentimeline_opentimelineio_Algorithms_trackTrimmedToRange
58-
(JNIEnv *env, jobject thisObj, jobject inTrack, jobject trimRangeObj, jobject errorStatusObj) {
59-
if (inTrack == nullptr || trimRangeObj == nullptr ||
60-
errorStatusObj == nullptr) {
54+
(JNIEnv *env, jobject thisObj, jobject inTrack, jobject trimRangeObj) {
55+
if (inTrack == nullptr || trimRangeObj == nullptr) {
6156
throwNullPointerException(env, "");
6257
return nullptr;
6358
}
6459
auto inTrackHandle =
6560
getHandle<SerializableObject::Retainer<Track>>(env, inTrack);
6661
auto track = inTrackHandle->value;
6762
auto trimRange = timeRangeFromJObject(env, trimRangeObj);
68-
auto errorStatusHandle =
69-
getHandle<OTIO_NS::ErrorStatus>(env, errorStatusObj);
63+
auto errorStatus = OTIO_NS::ErrorStatus();
7064
auto result = track_trimmed_to_range(
71-
track, trimRange, errorStatusHandle);
65+
track, trimRange, &errorStatus);
66+
processOTIOErrorStatus(env, errorStatus);
7267
return trackFromNative(env, result);
7368
}

src/main/cpp/io_opentimeline_opentimelineio_AnyVector.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ JNIEXPORT jobjectArray JNICALL Java_io_opentimeline_opentimelineio_AnyVector_get
3737
env->NewObjectArray((jsize)thisHandle->size(), anyClass, nullptr);
3838
for (int i = 0; i < thisHandle->size(); i++) {
3939
auto newObj = anyFromNative(env, &thisHandle->at(i));
40-
registerObjectToOTIOFactory(env, newObj);
40+
// registerObjectToOTIOFactory(env, newObj);
4141
env->SetObjectArrayElement(
4242
result, i, newObj);
4343
}

src/main/cpp/io_opentimeline_opentimelineio_Clip.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,20 +83,16 @@ Java_io_opentimeline_opentimelineio_Clip_getMediaReference(
8383
/*
8484
* Class: io_opentimeline_opentimelineio_Clip
8585
* Method: getAvailableRange
86-
* Signature: (Lio/opentimeline/opentimelineio/ErrorStatus;)Lio/opentimeline/opentime/TimeRange;
86+
* Signature: ()Lio/opentimeline/opentime/TimeRange;
8787
*/
8888
JNIEXPORT jobject JNICALL
8989
Java_io_opentimeline_opentimelineio_Clip_getAvailableRange(
90-
JNIEnv *env, jobject thisObj, jobject errorStatusObj) {
91-
if (errorStatusObj == nullptr) {
92-
throwNullPointerException(env, "");
93-
return nullptr;
94-
}
90+
JNIEnv *env, jobject thisObj) {
9591
auto thisHandle =
9692
getHandle<SerializableObject::Retainer<Clip>>(env, thisObj);
9793
auto clip = thisHandle->value;
98-
auto errorStatusHandle =
99-
getHandle<OTIO_NS::ErrorStatus>(env, errorStatusObj);
100-
auto result = clip->available_range(errorStatusHandle);
94+
auto errorStatus = OTIO_NS::ErrorStatus();
95+
auto result = clip->available_range(&errorStatus);
96+
processOTIOErrorStatus(env, errorStatus);
10197
return timeRangeToJObject(env, result);
10298
}

0 commit comments

Comments
 (0)