From 1280b66f419a92fc04be3e9e61be6c40d5ef08f6 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Thu, 12 Aug 2021 10:11:46 +0200 Subject: [PATCH] Catch blurhash decoding errors Signed-off-by: Thomas Citharel --- js/src/components/Event/EventBanner.vue | 3 ++- js/src/components/Image/BlurhashImg.vue | 14 +++++++++----- js/src/components/Image/LazyImageWrapper.vue | 3 ++- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/js/src/components/Event/EventBanner.vue b/js/src/components/Event/EventBanner.vue index 1e82f0c38..f2d429ab2 100644 --- a/js/src/components/Event/EventBanner.vue +++ b/js/src/components/Event/EventBanner.vue @@ -5,6 +5,7 @@ diff --git a/js/src/components/Image/BlurhashImg.vue b/js/src/components/Image/BlurhashImg.vue index 9181991a1..a4017a5fc 100644 --- a/js/src/components/Image/BlurhashImg.vue +++ b/js/src/components/Image/BlurhashImg.vue @@ -7,17 +7,21 @@ import { decode } from "blurhash"; import { Component, Prop, Ref, Vue } from "vue-property-decorator"; @Component -export default class extends Vue { +export default class BlurhashImg extends Vue { @Prop({ type: String, required: true }) hash!: string; @Prop({ type: Number, default: 1 }) aspectRatio!: string; @Ref("canvas") readonly canvas!: any; mounted(): void { - const pixels = decode(this.hash, 32, 32); - const imageData = new ImageData(pixels, 32, 32); - const context = this.canvas.getContext("2d"); - context.putImageData(imageData, 0, 0); + try { + const pixels = decode(this.hash, 32, 32); + const imageData = new ImageData(pixels, 32, 32); + const context = this.canvas.getContext("2d"); + context.putImageData(imageData, 0, 0); + } catch (e) { + console.error(e); + } } } diff --git a/js/src/components/Image/LazyImageWrapper.vue b/js/src/components/Image/LazyImageWrapper.vue index af5b43493..1b3e1313a 100644 --- a/js/src/components/Image/LazyImageWrapper.vue +++ b/js/src/components/Image/LazyImageWrapper.vue @@ -9,6 +9,7 @@