Skip to content

Commit

Permalink
Merge pull request #235 from atsign-foundation/exception_trace_bug
Browse files Browse the repository at this point in the history
fix: check size of chained exception list in getTraceMessage
  • Loading branch information
murali-shris committed Sep 27, 2022
2 parents cfda88a + d2d9c2a commit 2acf31f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
1 change: 1 addition & 0 deletions at_commons/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 4 additions & 2 deletions at_commons/lib/src/exception/at_exception_stack.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ class AtExceptionStack implements Comparable<AtChainedException> {
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;
Expand Down
32 changes: 32 additions & 0 deletions at_commons/test/at_exception_stack_test.dart
Original file line number Diff line number Diff line change
@@ -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'));
});
});
}

0 comments on commit 2acf31f

Please sign in to comment.