Skip to content

Commit 58f542d

Browse files
authored
Merge pull request #312 from basho/features/lrb/dont-lose-error-messages-gh-311
Preserve error text.
2 parents 19702cd + d0a3a09 commit 58f542d

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

src/ChaosMonkeyApp/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ private static void FetchServerInfo()
108108
var rsp = cmd.Response;
109109
var n = rsp.Value.Node;
110110
var v = rsp.Value.ServerVersion;
111-
Console.WriteLine("[ChaosMonkeyApp] got server info: {0}, {1}", n, v);
111+
// Console.WriteLine("[ChaosMonkeyApp] got server info: {0}, {1}", n, v);
112112
}
113113
else
114114
{

src/RiakClient/Exceptions/RiakException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public RiakException(string message, Exception innerException)
6767
/// <param name="message">A message that describes the error.</param>
6868
/// <param name="nodeOffline">A flag to mark if the node was offline or unreachable at the time of the error.</param>
6969
public RiakException(int errorCode, string message, bool nodeOffline)
70-
: this(string.Format("Riak returned an error. Code '{0}'. Message: {1}", errorCode, message))
70+
: this(string.Format("Riak returned an error. Code '{0}'. Message: '{1}'", errorCode, message))
7171
{
7272
this.nodeOffline = nodeOffline;
7373
this.errorCode = errorCode;

src/RiakClient/RiakCluster.cs

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,21 +125,23 @@ public override RiakResult<IEnumerable<TResult>> UseDelayedConnection<TResult>(F
125125
{
126126
if (retryAttempts < 0)
127127
{
128-
return RiakResult<IEnumerable<TResult>>.FromError(ResultCode.NoRetries, "Unable to access a connection on the cluster.", false);
128+
return RiakResult<IEnumerable<TResult>>.FromError(ResultCode.NoRetries, "Unable to access a connection on the cluster (no more retries).", false);
129129
}
130130

131131
if (disposing)
132132
{
133133
return RiakResult<IEnumerable<TResult>>.FromError(ResultCode.ShuttingDown, "System currently shutting down", true);
134134
}
135135

136+
var errorMessages = new List<string>();
136137
var node = loadBalancer.SelectNode();
137-
138138
if (node != null)
139139
{
140140
var result = node.UseDelayedConnection(useFun);
141141
if (!result.IsSuccess)
142142
{
143+
errorMessages.Add(result.ErrorMessage);
144+
143145
if (result.ResultCode == ResultCode.NoConnections)
144146
{
145147
Thread.Sleep(RetryWaitTime);
@@ -157,7 +159,8 @@ public override RiakResult<IEnumerable<TResult>> UseDelayedConnection<TResult>(F
157159
return result;
158160
}
159161

160-
return RiakResult<IEnumerable<TResult>>.FromError(ResultCode.ClusterOffline, "Unable to access functioning Riak node", true);
162+
string msg = string.Format("Unable to access functioning Riak node, error(s): {0}", string.Join(", ", errorMessages));
163+
return RiakResult<IEnumerable<TResult>>.FromError(ResultCode.ClusterOffline, msg, true);
161164
}
162165

163166
protected override void Dispose(bool disposing)
@@ -196,7 +199,7 @@ protected override TRiakResult UseConnection<TRiakResult>(
196199
{
197200
if (retryAttempts < 0)
198201
{
199-
return onError(ResultCode.NoRetries, "Unable to access a connection on the cluster.", false);
202+
return onError(ResultCode.NoRetries, "Unable to access a connection on the cluster (no more retries).", false);
200203
}
201204

202205
if (disposing)
@@ -207,9 +210,12 @@ protected override TRiakResult UseConnection<TRiakResult>(
207210
var node = loadBalancer.SelectNode();
208211
if (node != null)
209212
{
213+
var errorMessages = new List<string>();
210214
var result = node.UseConnection(useFun);
211215
if (!result.IsSuccess)
212216
{
217+
errorMessages.Add(result.ErrorMessage);
218+
213219
TRiakResult nextResult = null;
214220
if (result.ResultCode == ResultCode.NoConnections)
215221
{
@@ -223,21 +229,29 @@ protected override TRiakResult UseConnection<TRiakResult>(
223229
nextResult = UseConnection(useFun, onError, retryAttempts - 1);
224230
}
225231

226-
// if the next result is successful then return that
227-
if (nextResult != null && nextResult.IsSuccess)
232+
if (nextResult != null)
228233
{
229-
return nextResult;
234+
// if the next result is successful then return that
235+
if (nextResult.IsSuccess)
236+
{
237+
return nextResult;
238+
}
239+
else
240+
{
241+
errorMessages.Add(nextResult.ErrorMessage);
242+
}
230243
}
231244

232245
// otherwise we'll return the result that we had at this call to make sure that
233246
// the correct/initial error is shown
234-
return onError(result.ResultCode, result.ErrorMessage, result.NodeOffline);
247+
string errorMessage = string.Join(", ", errorMessages);
248+
return onError(result.ResultCode, errorMessage, result.NodeOffline);
235249
}
236250

237251
return (TRiakResult)result;
238252
}
239253

240-
return onError(ResultCode.ClusterOffline, "Unable to access functioning Riak node", true);
254+
return onError(ResultCode.ClusterOffline, "Unable to access functioning Riak node (load balancer returned no nodes).", true);
241255
}
242256

243257
private void MaybeDeactivateNode(bool nodeOffline, IRiakNode node)

0 commit comments

Comments
 (0)