ImagesPlugin print a warning for SVG and GIF instead of full stacktrace

This commit is contained in:
Dimitry Ivanov 2019-08-26 13:53:39 +03:00
parent fa01a50ae8
commit 1b7fbfb77f
4 changed files with 35 additions and 10 deletions

View File

@ -11,7 +11,6 @@ import java.io.InputStream;
import java.util.Collection;
import java.util.Collections;
import io.noties.markwon.image.DrawableUtils;
import io.noties.markwon.image.MediaDecoder;
import pl.droidsonroids.gif.GifDrawable;
@ -97,9 +96,7 @@ public class GifMediaDecoder extends MediaDecoder {
private static void validate() {
if (!GifSupport.hasGifSupport()) {
throw new IllegalStateException("`pl.droidsonroids.gif:android-gif-drawable:*` " +
"dependency is missing, please add to your project explicitly if you " +
"wish to use GIF media decoder");
throw new IllegalStateException(GifSupport.missingMessage());
}
}
}

View File

@ -1,5 +1,9 @@
package io.noties.markwon.image.gif;
import android.util.Log;
import androidx.annotation.NonNull;
/**
* @since 4.0.0
*/
@ -13,8 +17,9 @@ public abstract class GifSupport {
pl.droidsonroids.gif.GifDrawable.class.getName();
result = true;
} catch (Throwable t) {
// @since 4.1.1-SNAPSHOT do not print stacktrace (it can become noisy)
// t.printStackTrace();
// @since 4.1.1-SNAPSHOT instead of printing full stacktrace of the exception,
// just print a warning to the console
Log.w("MarkwonImagesPlugin", missingMessage());
result = false;
}
HAS_GIF = result;
@ -24,6 +29,16 @@ public abstract class GifSupport {
return HAS_GIF;
}
/**
* @since 4.1.1-SNAPSHOT
*/
@NonNull
static String missingMessage() {
return "`pl.droidsonroids.gif:android-gif-drawable:*` " +
"dependency is missing, please add to your project explicitly if you " +
"wish to use GIF media-decoder";
}
private GifSupport() {
}
}

View File

@ -83,8 +83,7 @@ public class SvgMediaDecoder extends MediaDecoder {
private static void validate() {
if (!SvgSupport.hasSvgSupport()) {
throw new IllegalStateException("`com.caverock:androidsvg:*` dependency is missing, " +
"please add to your project explicitly if you wish to use SVG media decoder");
throw new IllegalStateException(SvgSupport.missingMessage());
}
}
}

View File

@ -1,5 +1,9 @@
package io.noties.markwon.image.svg;
import android.util.Log;
import androidx.annotation.NonNull;
/**
* @since 4.0.0
*/
@ -13,8 +17,9 @@ public abstract class SvgSupport {
com.caverock.androidsvg.SVG.class.getName();
result = true;
} catch (Throwable t) {
// @since 4.1.1-SNAPSHOT do not print stacktrace (it can become noisy)
// t.printStackTrace();
// @since 4.1.1-SNAPSHOT instead of printing full stacktrace of the exception,
// just print a warning to the console
Log.w("MarkwonImagesPlugin", missingMessage());
result = false;
}
HAS_SVG = result;
@ -24,6 +29,15 @@ public abstract class SvgSupport {
return HAS_SVG;
}
/**
* @since 4.1.1-SNAPSHOT
*/
@NonNull
static String missingMessage() {
return "`com.caverock:androidsvg:*` dependency is missing, " +
"please add to your project explicitly if you wish to use SVG media-decoder";
}
private SvgSupport() {
}
}