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 { ...@@ -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 * <p>If there is a corresponding {@link TransformationException.ErrorCode} for the {@link
* #ERROR_CODE_UNSPECIFIED}. * 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( /* package */ static TransformationException createForPlaybackException(
PlaybackException exception) { PlaybackException exception) {
return new TransformationException( @ErrorCode int errorCode = getErrorCodeForName(exception.getErrorCodeName());
exception.getMessage(), return errorCode == ERROR_CODE_UNSPECIFIED
exception.getCause(), ? createForUnexpected(exception)
getErrorCodeForName(exception.getErrorCodeName())); : new TransformationException(exception.getMessage(), exception, errorCode);
} }
/** An error code which identifies the cause of the transformation failure. */ /** An error code which identifies the cause of the transformation failure. */
......
...@@ -340,7 +340,8 @@ public final class TransformerTest { ...@@ -340,7 +340,8 @@ public final class TransformerTest {
transformer.startTransformation(mediaItem, outputPath); transformer.startTransformation(mediaItem, outputPath);
TransformationException exception = TransformerTestRunner.runUntilError(transformer); 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 @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