diff --git a/lib/command.dart b/lib/command.dart index d7d7dcf..bb68f10 100644 --- a/lib/command.dart +++ b/lib/command.dart @@ -24,8 +24,14 @@ class Command { /// send_object(["SET","key","value"]); Future send_object(Object obj) { try { - // RedisSerialise.Serialise - return _connection._sendraw(RedisSerialise.Serialise(obj)); + return _connection._sendraw(RedisSerialise.Serialise(obj)).then((v) { + // turn RedisError into exception + if (v is RedisError) { + return Future.error(v); + } else { + return v; + } + }); } catch (e) { return Future.error(e); } diff --git a/lib/redisparser.dart b/lib/redisparser.dart index 15c5647..72db062 100644 --- a/lib/redisparser.dart +++ b/lib/redisparser.dart @@ -62,7 +62,7 @@ class RedisParser { case TYPE_BULK: return parseBulk(s); case TYPE_ERROR: - return parseError(s).then((e) => Future.error(e)); + return parseError(s); default: return Future.error( RedisRuntimeError("got element that cant not be parsed")); diff --git a/test/error_test.dart b/test/error_test.dart index 665fec4..ac805f7 100644 --- a/test/error_test.dart +++ b/test/error_test.dart @@ -11,6 +11,16 @@ main() { expect(cmd.send_object("GARBAGE"), throwsA(isRedisError)); }); }); + + group("Recover after received Redis Errors", () { + test("Expect error when sending Garbage 2", () async { + Command cmd = await generate_connect(); + expect(cmd.send_object(["GARBAGE"]), throwsA(isRedisError)); + // next two commands over same connection should be fine + expect(await cmd.send_object(["SET","garbage_test","grb"]),equals("OK")); + expect(await cmd.send_object(["GET","garbage_test"]),equals("grb")); + }); + }); } const Matcher isRedisError = TypeMatcher();