Wrap PlaybackExceptions in TransformationExceptions.
PiperOrigin-RevId: 420032157
This commit is contained in:
parent
a8e44294ab
commit
dfcb906d84
@ -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 {
|
|||||||
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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user