From 51f666533ee3dc2c893b06bcf1888e412be6a05c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C5=BEe=20Vovk?= Date: Tue, 17 Dec 2024 20:14:16 +0100 Subject: [PATCH] Hiding invalid barcode output and continuing the SVG rendering process. Maybe I should be adding error messages at the barcode location instead? --- zpl2svg.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/zpl2svg.js b/zpl2svg.js index 78d1b86..c29a012 100644 --- a/zpl2svg.js +++ b/zpl2svg.js @@ -89,7 +89,7 @@ svg.push(``) svg.push(``) svg.push(``) - + // Track inversion regions let inversionMasks = [] @@ -211,7 +211,7 @@ rotate: state.barcode.orientation === 'B' ? 'L' : state.barcode.orientation, } if (alttext && state.barcode.print_human_readable) barcode_options.alttext = alttext - if (bcid === 'azteccode') { + if (bcid === 'azteccode') { // @ts-ignore delete barcode_options.height barcode_options.scale *= state.barcode.magnification / 4 barcode_options.format = 'full' @@ -229,7 +229,15 @@ } // @ts-ignore - const barcode = bwipjs.toSVG(barcode_options) + let barcode = '' + try { + barcode = bwipjs.toSVG(barcode_options) + } catch (e) { + console.log(`Failed to generate barcode: ${state.barcode.type} with value: ${value}`) + console.log(e) + state.barcode.type = '' // Reset barcode type to prevent drawing barcode on next text field + break + } //