From 5644f9f0cbbfe991f4025cf567ccaa23773fdca7 Mon Sep 17 00:00:00 2001 From: Alexandre Jacinto Date: Wed, 2 Dec 2026 08:57:32 -0400 Subject: [PATCH] fix: report INVALID_PARAMETERS_ERROR instead of a generic scanning error OSBARCController.handleActivityResult had no branch for the INVALID_PARAMETERS_ERROR result code, so the error finished by OSBARCScannerActivity when SCAN_PARAMETERS is missing (#58) was reported to callers as SCANNING_GENERAL_ERROR. Map it, add a unit test and the changelog entry for #58. --- CHANGELOG.md | 3 +++ .../plugins/barcode/controller/OSBARCController.kt | 2 ++ .../outsystems/plugins/barcode/ScanCodeTests.kt | 14 ++++++++++++++ 3 files changed, 19 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e29c79c..ae68a6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ The changes documented here do not include those from the original repository. ## [Unreleased] +### 2026-12-02 +- Fix: avoid a crash when the scan parameters are missing from the scanner activity's intent; the scan now fails with the "Scanning parameters are invalid" error instead of a generic scanning error (https://github.com/OutSystems/OSBarcodeLib-Android/pull/58). + ## [2.1.2] ### 2026-10-30 diff --git a/src/main/kotlin/com/outsystems/plugins/barcode/controller/OSBARCController.kt b/src/main/kotlin/com/outsystems/plugins/barcode/controller/OSBARCController.kt index 81aaefe..50266b0 100644 --- a/src/main/kotlin/com/outsystems/plugins/barcode/controller/OSBARCController.kt +++ b/src/main/kotlin/com/outsystems/plugins/barcode/controller/OSBARCController.kt @@ -76,6 +76,8 @@ class OSBARCController { onError(OSBARCError.ZXING_LIBRARY_ERROR) OSBARCError.MLKIT_LIBRARY_ERROR.code -> onError(OSBARCError.MLKIT_LIBRARY_ERROR) + OSBARCError.INVALID_PARAMETERS_ERROR.code -> + onError(OSBARCError.INVALID_PARAMETERS_ERROR) else -> { Log.d(LOG_TAG, "Invalid result code") onError(OSBARCError.SCANNING_GENERAL_ERROR) diff --git a/src/test/kotlin/com/outsystems/plugins/barcode/ScanCodeTests.kt b/src/test/kotlin/com/outsystems/plugins/barcode/ScanCodeTests.kt index 5d366ed..197512a 100644 --- a/src/test/kotlin/com/outsystems/plugins/barcode/ScanCodeTests.kt +++ b/src/test/kotlin/com/outsystems/plugins/barcode/ScanCodeTests.kt @@ -206,6 +206,20 @@ class ScanCodeTests { ) } + @Test + fun givenInvalidParametersResultCodeWhenHandleScanResultThenInvalidParametersError() { + val barcodeController = OSBARCController() + barcodeController.handleActivityResult(SCAN_REQUEST_CODE, OSBARCError.INVALID_PARAMETERS_ERROR.code, mockIntent, + { + fail() + }, + { + assertEquals(OSBARCError.INVALID_PARAMETERS_ERROR.code, it.code) + assertEquals(OSBARCError.INVALID_PARAMETERS_ERROR.description, it.description) + } + ) + } + @Test fun givenResultOKAndBarcodeEmptyWhenHandleScanResultThenScanningError() { mockIntentCompat