Skip to content

Commit

Permalink
Improve exception handling #15
Browse files Browse the repository at this point in the history
  • Loading branch information
ra1u committed Sep 22, 2019
1 parent 7e135cd commit 9c66e8b
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 12 deletions.
9 changes: 7 additions & 2 deletions lib/cas.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,14 @@ class Cas{
_completer_bool.complete(false); //terminate Future.doWhile
}
else{
_completer_bool.complete(true);
// exec completes only with valid response
_completer_bool.completeError(RedisError("exec response is not expceted, but is $resp"));
}
});
})
.catchError((e){
// dont do anything
_completer_bool.complete(true); // retry
}, test: (e) => e is TransactionError);
});
}
}
25 changes: 25 additions & 0 deletions lib/exceptions.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Free software licenced under
* GNU AFFERO GENERAL PUBLIC LICENSE
*
* Check for document LICENCE forfull licence text
*
* Luka Rahne
*/

part of redis;


class RedisError {
String e;
RedisError(this.e);
String toString() { return "RedisError($e)";}
}


class TransactionError {
String e;
TransactionError(this.e);
String toString() { return "TranscationError($e)";}
}

1 change: 1 addition & 0 deletions lib/redis.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ part './redisparser.dart';
part './command.dart';
part './pubsub.dart';
part './cas.dart';
part './exceptions.dart';
6 changes: 0 additions & 6 deletions lib/redisparser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@

part of redis;

class RedisError{
String e;
RedisError(this.e);
String toString() { return "RedisError($e)";}
}


class RedisParser{
static final UTF8 = const Utf8Codec();
Expand Down
6 changes: 2 additions & 4 deletions lib/transaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,12 @@ class Transaction extends Command{
transaction_completed = true;
return super.send_object(["EXEC"])
.then((list){

if(list == null){ //we got explicit error from redis
while(_queue.isNotEmpty){
Completer c =_queue.removeFirst();
c.complete(new RedisError("Transaction terminated"));
return null;
}
return null;
throw TransactionError("transaction error ");
//return null;
}
else{
if(list.length != _queue.length){
Expand Down

0 comments on commit 9c66e8b

Please sign in to comment.