Skip to content

Commit

Permalink
Update AtExceptionStack
Browse files Browse the repository at this point in the history
  • Loading branch information
sitaram-kalluri committed May 19, 2022
1 parent fe59b66 commit 52ba744
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 14 deletions.
50 changes: 43 additions & 7 deletions at_commons/lib/src/exception/at_client_exceptions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,65 @@ class AtClientException extends AtException {
AtClientException(errorCode, message) : super(message);

/// The named constructor that takes only message
AtClientException.message(message) : super(message);
AtClientException.message(message,
{Intent? intent, ExceptionScenario? exceptionScenario})
: super(message, intent: intent, exceptionScenario: exceptionScenario);
}

class AtKeyException extends AtClientException {
AtKeyException(message) : super.message(message);
AtKeyException(message,
{Intent? intent, ExceptionScenario? exceptionScenario})
: super.message(message,
intent: intent, exceptionScenario: exceptionScenario);
}

class AtValueException extends AtClientException {
AtValueException(message) : super.message(message);
AtValueException(message,
{Intent? intent, ExceptionScenario? exceptionScenario})
: super.message(message,
intent: intent, exceptionScenario: exceptionScenario);
}

class AtEncryptionException extends AtClientException {
AtEncryptionException(message) : super.message(message);
AtEncryptionException(message,
{Intent? intent, ExceptionScenario? exceptionScenario})
: super.message(message,
intent: intent, exceptionScenario: exceptionScenario);
}

class AtPublicKeyChangeException extends AtEncryptionException {
AtPublicKeyChangeException(message) : super(message);
AtPublicKeyChangeException(message,
{Intent? intent, ExceptionScenario? exceptionScenario})
: super(message, intent: intent, exceptionScenario: exceptionScenario);
}

class AtPublicKeyNotFoundException extends AtEncryptionException {
AtPublicKeyNotFoundException(message) : super(message);
AtPublicKeyNotFoundException(message,
{Intent? intent, ExceptionScenario? exceptionScenario})
: super(message, intent: intent, exceptionScenario: exceptionScenario);
}

class AtDecryptionException extends AtClientException {
AtDecryptionException(message) : super.message(message);
AtDecryptionException(message,
{Intent? intent, ExceptionScenario? exceptionScenario})
: super.message(message,
intent: intent, exceptionScenario: exceptionScenario);
}

class AtPrivateKeyNotFoundException extends AtDecryptionException {
AtPrivateKeyNotFoundException(message,
{Intent? intent, ExceptionScenario? exceptionScenario})
: super(message, intent: intent, exceptionScenario: exceptionScenario);
}

class SharedKeyNotFoundException extends AtDecryptionException {
SharedKeyNotFoundException(message,
{Intent? intent, ExceptionScenario? exceptionScenario})
: super(message, intent: intent, exceptionScenario: exceptionScenario);
}

class SelfKeyNotFoundException extends AtDecryptionException {
SelfKeyNotFoundException(message,
{Intent? intent, ExceptionScenario? exceptionScenario})
: super(message, intent: intent, exceptionScenario: exceptionScenario);
}
11 changes: 7 additions & 4 deletions at_commons/lib/src/exception/at_exception_stack.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class AtExceptionStack implements Comparable<AtChainedException> {
'${getIntentMessage(_exceptionList.first.intent)} caused by\n';
for (AtChainedException element in _exceptionList) {
size--;
fullMessage += '${element.atException.message}';
fullMessage += element.message;
if (size != 0) {
fullMessage += ' caused by\n';
}
Expand All @@ -37,13 +37,16 @@ class AtExceptionStack implements Comparable<AtChainedException> {
if (intent == Intent.shareData) {
return 'Failed to share data';
}
if(intent == Intent.decryptData) {
return 'Failed to decrypt the data';
}
return 'Failed to notify data';
}

@override
int compareTo(AtChainedException atChainedException) {
for (var element in _exceptionList) {
if (element.atException == atChainedException.atException) {
if (element.message == atChainedException.message) {
return 0;
}
}
Expand All @@ -54,7 +57,7 @@ class AtExceptionStack implements Comparable<AtChainedException> {
class AtChainedException {
late Intent intent;
late ExceptionScenario exceptionScenario;
late AtException atException;
late String message;

AtChainedException(this.intent, this.exceptionScenario, this.atException);
AtChainedException(this.intent, this.exceptionScenario, this.message);
}
21 changes: 18 additions & 3 deletions at_commons/lib/src/exception/at_exceptions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,17 @@ class AtException implements Exception {
/// Represents error message that details the cause of the exception
var message;

Intent? intent;

ExceptionScenario? exceptionScenario;

AtExceptionStack _traceStack = AtExceptionStack();

AtException(this.message);
AtException(this.message, {this.intent, this.exceptionScenario}) {
if (intent != null && exceptionScenario != null) {
_traceStack.add(AtChainedException(intent!, exceptionScenario!, message));
}
}

AtException fromException(AtException atException) {
_traceStack = atException._traceStack;
Expand Down Expand Up @@ -188,13 +196,20 @@ enum ExceptionScenario {
decryptionFailed,
remoteVerbExecutionFailed,
localVerbExecutionFailed,
atSignDoesNotExist
atSignDoesNotExist,
fetchEncryptionKeys
}

enum Intent {
shareData,
fetchData,
validateKey,
validateAtSign,
remoteVerbExecution
remoteVerbExecution,
notifyData,
decryptData,
fetchEncryptionPublicKey,
fetchEncryptionPrivateKey,
fetchEncryptionSharedKey,
fetchSelfEncryptionKey
}

0 comments on commit 52ba744

Please sign in to comment.