public TsTtbResp(byte[] response) { if (response == null) { throw new ArgumentNullException("response"); } this.response = response; RiakException ex = TtbErrorDecoder.MaybeRiakError(response); if (ex != null) { throw ex; } }
public void GettingExtendedPropertiesOnInvalidBucketReturnsError() { var bucketName = string.Format("{0}_{1}", Bucket, "this/is/not/a/valid/bucket"); RiakException exception = null; try { var getResult = Client.GetBucketProperties(bucketName); } catch (RiakException riakException) { exception = riakException; } exception.ShouldNotBeNull(); exception.ErrorCode.ShouldEqual((uint)ResultCode.InvalidRequest); }
public void SettingExtendedPropertiesToBucketWithSlashesInNameShouldReturnError() { var bucketName = string.Format("{0}_{1}", Bucket, "not/valid/here"); var props = new RiakBucketProperties() .SetNVal(4) .SetSearch(true) .SetWVal("all") .SetRVal("quorum"); RiakException exception = null; try { var getResult = Client.SetBucketProperties(bucketName, props); } catch (RiakException riakException) { exception = riakException; } exception.ShouldNotBeNull(); exception.ErrorCode.ShouldEqual((uint)ResultCode.InvalidRequest); }
public static RiakException MaybeRiakError(byte[] response) { RiakException rv = null; if (EnumerableUtil.IsNullOrEmpty(response)) { string errMsg = "TTB request returned null or zero-length data buffer."; rv = new RiakException(0, errMsg, false); } using (var s = new OtpInputStream(response)) { string atom; byte tag = s.Peek1SkipVersion(); switch (tag) { case OtpExternal.AtomTag: atom = s.ReadAtom(); if (atom.Equals(RpbErrorRespAtom)) { throw new RiakException(0, RpbErrorRespEmpty, false); } break; case OtpExternal.SmallTupleTag: case OtpExternal.LargeTupleTag: int arity = s.ReadTupleHead(); if (arity >= 1) { tag = s.Peek(); if (tag == OtpExternal.AtomTag) { atom = s.ReadAtom(); if (atom.Equals(RpbErrorRespAtom)) { arity--; // We've read one item in the tuple string errMsg = RpbErrorRespEmpty; int errCode = 0; for (int i = 0; i < arity; ++i) { tag = s.Peek(); if (tag == OtpExternal.BinTag) { errMsg = s.ReadBinaryAsString(); } else if (s.IsLongTag(tag)) { errCode = (int)s.ReadLong(); } else { errMsg = string.Format("Unexpected tag {0} in {1}", tag, RpbErrorRespAtom); errCode = 0; break; } } rv = new RiakException(errCode, errMsg, false); } } } break; } } return rv; }
public static RiakException MaybeRiakError(byte[] response) { RiakException rv = null; if (EnumerableUtil.IsNullOrEmpty(response)) { string errMsg = "TTB request returned null or zero-length data buffer."; rv = new RiakException(0, errMsg, false); } using (var s = new OtpInputStream(response)) { string atom; byte tag = s.Peek1SkipVersion(); switch (tag) { case OtpExternal.AtomTag: atom = s.ReadAtom(); if (atom.Equals(RpbErrorRespAtom)) { throw new RiakException(0, RpbErrorRespEmpty, false); } break; case OtpExternal.SmallTupleTag: case OtpExternal.LargeTupleTag: int arity = s.ReadTupleHead(); if (arity >= 1) { tag = s.Peek(); if (tag == OtpExternal.AtomTag) { atom = s.ReadAtom(); if (atom.Equals(RpbErrorRespAtom)) { arity--; // We've read one item in the tuple string errMsg = RpbErrorRespEmpty; int errCode = 0; for (int i = 0; i < arity; ++i) { tag = s.Peek(); if (tag == OtpExternal.BinTag) { errMsg = s.ReadBinaryAsString(); } else if (s.IsLongTag(tag)) { errCode = (int)s.ReadLong(); } else { errMsg = string.Format("Unexpected tag {0} in {1}", tag, RpbErrorRespAtom); errCode = 0; break; } } rv = new RiakException(errCode, errMsg, false); } } } break; } } return(rv); }