From 08b5c4cb8331fbba13a51ac7139975db83853851 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Tue, 28 Apr 2020 10:26:32 +0200 Subject: [PATCH] Change ImageFormatException to InvalidImageContentException --- .../Exceptions/InvalidImageContentException.cs | 14 ++++++++++++++ src/ImageSharp/Formats/Bmp/BmpDecoder.cs | 4 +--- src/ImageSharp/Formats/Gif/GifDecoder.cs | 4 +--- src/ImageSharp/Formats/Jpeg/JpegDecoder.cs | 4 +--- src/ImageSharp/Formats/Png/PngDecoder.cs | 4 +--- src/ImageSharp/Formats/Tga/TgaDecoder.cs | 4 +--- 6 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/ImageSharp/Common/Exceptions/InvalidImageContentException.cs b/src/ImageSharp/Common/Exceptions/InvalidImageContentException.cs index 7069e89823..8be13919f1 100644 --- a/src/ImageSharp/Common/Exceptions/InvalidImageContentException.cs +++ b/src/ImageSharp/Common/Exceptions/InvalidImageContentException.cs @@ -1,6 +1,8 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. +using System; + namespace SixLabors.ImageSharp { /// @@ -18,5 +20,17 @@ namespace SixLabors.ImageSharp : base(errorMessage) { } + + /// + /// Initializes a new instance of the class with the name of the + /// parameter that causes this exception. + /// + /// The error message that explains the reason for this exception. + /// The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) + /// if no inner exception is specified. + public InvalidImageContentException(string errorMessage, Exception innerException) + : base(errorMessage, innerException) + { + } } } diff --git a/src/ImageSharp/Formats/Bmp/BmpDecoder.cs b/src/ImageSharp/Formats/Bmp/BmpDecoder.cs index a956f19c72..cafe101060 100644 --- a/src/ImageSharp/Formats/Bmp/BmpDecoder.cs +++ b/src/ImageSharp/Formats/Bmp/BmpDecoder.cs @@ -43,9 +43,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp { Size dims = decoder.Dimensions; - // TODO: use InvalidImageContentException here, if we decide to define it - // https://github.com/SixLabors/ImageSharp/issues/1110 - throw new ImageFormatException($"Can not decode image. Failed to allocate buffers for possibly degenerate dimensions: {dims.Width}x{dims.Height}. This error can happen for very large RLE bitmaps, which are not supported.", ex); + throw new InvalidImageContentException($"Can not decode image. Failed to allocate buffers for possibly degenerate dimensions: {dims.Width}x{dims.Height}. This error can happen for very large RLE bitmaps, which are not supported.", ex); } } diff --git a/src/ImageSharp/Formats/Gif/GifDecoder.cs b/src/ImageSharp/Formats/Gif/GifDecoder.cs index caa076553d..358d68e275 100644 --- a/src/ImageSharp/Formats/Gif/GifDecoder.cs +++ b/src/ImageSharp/Formats/Gif/GifDecoder.cs @@ -38,9 +38,7 @@ namespace SixLabors.ImageSharp.Formats.Gif { Size dims = decoder.Dimensions; - // TODO: use InvalidImageContentException here, if we decide to define it - // https://github.com/SixLabors/ImageSharp/issues/1110 - throw new ImageFormatException($"Can not decode image. Failed to allocate buffers for possibly degenerate dimensions: {dims.Width}x{dims.Height}.", ex); + throw new InvalidImageContentException($"Can not decode image. Failed to allocate buffers for possibly degenerate dimensions: {dims.Width}x{dims.Height}.", ex); } } diff --git a/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs b/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs index b1144508ec..424890cc2b 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegDecoder.cs @@ -32,9 +32,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg { (int w, int h) = (decoder.ImageWidth, decoder.ImageHeight); - // TODO: use InvalidImageContentException here, if we decide to define it - // https://github.com/SixLabors/ImageSharp/issues/1110 - throw new ImageFormatException($"Can not decode image. Failed to allocate buffers for possibly degenerate dimensions: {w}x{h}.", ex); + throw new InvalidImageContentException($"Can not decode image. Failed to allocate buffers for possibly degenerate dimensions: {w}x{h}.", ex); } } diff --git a/src/ImageSharp/Formats/Png/PngDecoder.cs b/src/ImageSharp/Formats/Png/PngDecoder.cs index d605577e77..74903bcc25 100644 --- a/src/ImageSharp/Formats/Png/PngDecoder.cs +++ b/src/ImageSharp/Formats/Png/PngDecoder.cs @@ -54,9 +54,7 @@ namespace SixLabors.ImageSharp.Formats.Png { Size dims = decoder.Dimensions; - // TODO: use InvalidImageContentException here, if we decide to define it - // https://github.com/SixLabors/ImageSharp/issues/1110 - throw new ImageFormatException($"Can not decode image. Failed to allocate buffers for possibly degenerate dimensions: {dims.Width}x{dims.Height}.", ex); + throw new InvalidImageContentException($"Can not decode image. Failed to allocate buffers for possibly degenerate dimensions: {dims.Width}x{dims.Height}.", ex); } } diff --git a/src/ImageSharp/Formats/Tga/TgaDecoder.cs b/src/ImageSharp/Formats/Tga/TgaDecoder.cs index c3b8526ceb..b61a6ae28e 100644 --- a/src/ImageSharp/Formats/Tga/TgaDecoder.cs +++ b/src/ImageSharp/Formats/Tga/TgaDecoder.cs @@ -28,9 +28,7 @@ namespace SixLabors.ImageSharp.Formats.Tga { Size dims = decoder.Dimensions; - // TODO: use InvalidImageContentException here, if we decide to define it - // https://github.com/SixLabors/ImageSharp/issues/1110 - throw new ImageFormatException($"Can not decode image. Failed to allocate buffers for possibly degenerate dimensions: {dims.Width}x{dims.Height}.", ex); + throw new InvalidImageContentException($"Can not decode image. Failed to allocate buffers for possibly degenerate dimensions: {dims.Width}x{dims.Height}.", ex); } }