From 9677e47680380f44bf28af8d78d9da3deaf8f04f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Bregar?= Date: Sun, 12 Apr 2026 00:24:41 +0200 Subject: [PATCH] Ignore scanner decode noise and log debug errors in dev --- src/features/labels/label-create-page.js | 20 +++++++++++++++----- src/features/stock/stock-detail-page.js | 20 +++++++++++++++----- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/features/labels/label-create-page.js b/src/features/labels/label-create-page.js index 1d592e4..3a55b3e 100644 --- a/src/features/labels/label-create-page.js +++ b/src/features/labels/label-create-page.js @@ -784,6 +784,9 @@ export function labelCreatePageData(store) { this.stopScanner(); this.scannerState.isLoading = true; + const shouldLogDecodeErrors = import.meta.env.DEV; + let lastDecodeErrorName = ''; + let lastDecodeErrorAt = 0; try { if (!this.scannerReader) { @@ -804,13 +807,20 @@ export function labelCreatePageData(store) { return; } - if (!error || error?.name === 'NotFoundException') { + if (error) { + // Continuous decode emits expected per-frame misses/errors before a valid barcode is found. + // Keep the modal quiet and only surface startup failures from the outer catch block. + if (shouldLogDecodeErrors) { + const errorName = String(error?.name || 'UnknownError'); + const now = Date.now(); + if (errorName !== lastDecodeErrorName || now - lastDecodeErrorAt > 2000) { + console.debug('[scanner] Ignoring frame decode error while scanning:', errorName, error?.message || ''); + lastDecodeErrorName = errorName; + lastDecodeErrorAt = now; + } + } return; } - - if (!this.scannerState.error) { - this.scannerState.error = this.normalizeScannerError(error); - } }, ); } catch (error) { diff --git a/src/features/stock/stock-detail-page.js b/src/features/stock/stock-detail-page.js index cf3fd6e..5a86760 100644 --- a/src/features/stock/stock-detail-page.js +++ b/src/features/stock/stock-detail-page.js @@ -470,6 +470,9 @@ export function stockDetailPageData(store) { this.stopScanner(); this.scannerState.isLoading = true; + const shouldLogDecodeErrors = import.meta.env.DEV; + let lastDecodeErrorName = ''; + let lastDecodeErrorAt = 0; try { if (!this.scannerReader) { @@ -490,13 +493,20 @@ export function stockDetailPageData(store) { return; } - if (!error || error?.name === 'NotFoundException') { + if (error) { + // Continuous decode emits expected per-frame misses/errors before a valid barcode is found. + // Keep the modal quiet and only surface startup failures from the outer catch block. + if (shouldLogDecodeErrors) { + const errorName = String(error?.name || 'UnknownError'); + const now = Date.now(); + if (errorName !== lastDecodeErrorName || now - lastDecodeErrorAt > 2000) { + console.debug('[scanner] Ignoring frame decode error while scanning:', errorName, error?.message || ''); + lastDecodeErrorName = errorName; + lastDecodeErrorAt = now; + } + } return; } - - if (!this.scannerState.error) { - this.scannerState.error = this.normalizeScannerError(error); - } }, ); } catch (error) {