From 7b9cafa8455c1f05c183bc652a71167e96353c5a Mon Sep 17 00:00:00 2001 From: murali-shris Date: Tue, 27 Sep 2022 16:59:57 +0530 Subject: [PATCH 1/2] fix: check size of chained exception list in getTraceMessage --- at_commons/CHANGELOG.md | 1 + at_commons/lib/src/exception/at_exception_stack.dart | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/at_commons/CHANGELOG.md b/at_commons/CHANGELOG.md index 3860df83..9212184c 100644 --- a/at_commons/CHANGELOG.md +++ b/at_commons/CHANGELOG.md @@ -1,5 +1,6 @@ ## 3.0.26 * feat: Introduce notifyFetch verb +* fix: bug in at_exception_stack.dart ## 3.0.25 * fix: update regex to correctly parse negative values in ttl and ttb * feat: add clientConfig to from verb syntax diff --git a/at_commons/lib/src/exception/at_exception_stack.dart b/at_commons/lib/src/exception/at_exception_stack.dart index 11c0fde7..f22e8bb2 100644 --- a/at_commons/lib/src/exception/at_exception_stack.dart +++ b/at_commons/lib/src/exception/at_exception_stack.dart @@ -17,8 +17,10 @@ class AtExceptionStack implements Comparable { String getTraceMessage() { var size = _exceptionList.length; String fullMessage = ''; - fullMessage = - '${getIntentMessage(_exceptionList.first.intent)} caused by\n'; + if (size > 0) { + fullMessage = + '${getIntentMessage(_exceptionList.first.intent)} caused by\n'; + } for (AtChainedException element in _exceptionList) { size--; fullMessage += element.message; From d2d9c2a320ab58bebc94ca6ce8d8d7cd02640af0 Mon Sep 17 00:00:00 2001 From: murali-shris Date: Tue, 27 Sep 2022 17:04:00 +0530 Subject: [PATCH 2/2] fix: add unit test --- at_commons/test/at_exception_stack_test.dart | 32 ++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 at_commons/test/at_exception_stack_test.dart diff --git a/at_commons/test/at_exception_stack_test.dart b/at_commons/test/at_exception_stack_test.dart new file mode 100644 index 00000000..ccb35072 --- /dev/null +++ b/at_commons/test/at_exception_stack_test.dart @@ -0,0 +1,32 @@ +import 'package:at_commons/at_commons.dart'; +import 'package:test/test.dart'; + +void main() { + group('A group of tests for exception stack', () { + test('chained exception list size greater than zero - check trace message', + () { + final atChainedException = AtChainedException( + Intent.syncData, ExceptionScenario.invalidKeyFormed, 'sync issue'); + final exceptionStack = AtExceptionStack(); + exceptionStack.add(atChainedException); + expect(exceptionStack.getTraceMessage(), isNotEmpty); + expect(exceptionStack.getTraceMessage(), + startsWith('Failed to syncData caused by')); + }); + + test('chained exception list size is zero', () { + final exceptionStack = AtExceptionStack(); + expect(exceptionStack.getTraceMessage(), isEmpty); + }); + + test('check intent message', () { + final atChainedException = AtChainedException( + Intent.syncData, ExceptionScenario.invalidKeyFormed, 'sync issue'); + final exceptionStack = AtExceptionStack(); + exceptionStack.add(atChainedException); + expect(exceptionStack.getIntentMessage(Intent.syncData), isNotEmpty); + expect(exceptionStack.getIntentMessage(Intent.syncData), + equals('Failed to syncData')); + }); + }); +}