Commit dfcb906d by hschlueter Committed by Oliver Woodman

Wrap PlaybackExceptions in TransformationExceptions.

PiperOrigin-RevId: 420032157
parent a8e44294
......@@ -284,17 +284,18 @@ public final class TransformationException extends Exception {
}
/**
* Converts a {@link PlaybackException} to a {@code TransformationException}.
* Creates an instance for a {@link PlaybackException}.
*
* <p>If no corresponding error code exists, the created instance will have {@link
* #ERROR_CODE_UNSPECIFIED}.
* <p>If there is a corresponding {@link TransformationException.ErrorCode} for the {@link
* PlaybackException.ErrorCode}, this error code and the same message are used for the created
* instance. Otherwise, this is equivalent to {@link #createForUnexpected(Exception)}.
*/
/* package */ static TransformationException createForPlaybackException(
PlaybackException exception) {
return new TransformationException(
exception.getMessage(),
exception.getCause(),
getErrorCodeForName(exception.getErrorCodeName()));
@ErrorCode int errorCode = getErrorCodeForName(exception.getErrorCodeName());
return errorCode == ERROR_CODE_UNSPECIFIED
? createForUnexpected(exception)
: new TransformationException(exception.getMessage(), exception, errorCode);
}
/** An error code which identifies the cause of the transformation failure. */
......
......@@ -340,7 +340,8 @@ public final class TransformerTest {
transformer.startTransformation(mediaItem, outputPath);
TransformationException exception = TransformerTestRunner.runUntilError(transformer);
assertThat(exception).hasCauseThat().isInstanceOf(IOException.class);
assertThat(exception).hasCauseThat().hasCauseThat().isInstanceOf(IOException.class);
assertThat(exception.errorCode).isEqualTo(TransformationException.ERROR_CODE_IO_FILE_NOT_FOUND);
}
@Test
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment