Skip to content

Commit

Permalink
Fixes #601
Browse files Browse the repository at this point in the history
Fixes #602
  • Loading branch information
borrrden committed Mar 2, 2016
1 parent b60dda0 commit a9ec1f5
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 35 deletions.
8 changes: 4 additions & 4 deletions src/Couchbase.Lite.Shared/Replication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1280,9 +1280,7 @@ internal HttpRequestMessage SendAsyncRequest(HttpMethod method, Uri url, Object
if(response.IsCanceled) {
error = new Exception("SendAsyncRequest Task has been canceled.");
} else {
error = error is AggregateException
? response.Exception.Flatten()
: response.Exception;
error = Misc.Flatten(response.Exception);
}
if(error == null) {
Expand Down Expand Up @@ -1725,8 +1723,10 @@ private void FetchRemoteCheckpointDoc()
Log.To.Sync.I(TAG, "{0} replicating from lastSequence={1}", this, LastSequence);
} else {
Log.To.Sync.I(TAG, "{0} lastSequence mismatch: I had {1}, remote had {2} (response = {3}",
Log.To.Sync.I(TAG, "{0} lastSequence mismatch: I had {1}, remote had {2} (response = {3}, " +
"resetting lastSequence to 0",
this, localLastSequence, remoteLastSequence, response);
_lastSequence = "0";
}
BeginReplicating ();
Expand Down
26 changes: 6 additions & 20 deletions src/Couchbase.Lite.Shared/Util/CustomLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,6 @@ public CustomLogger()

#endregion

#region Private Methods

private static Exception Flatten(Exception tr)
{
if (!(tr is AggregateException)) {
return tr;
}

var err = ((AggregateException)tr).Flatten().InnerException;
return err;
}

#endregion

#region ILogger

public void V(string tag, string msg)
Expand All @@ -101,7 +87,7 @@ public void V(string tag, string msg, Exception tr)
}

lock (_locker) {
_ts.WriteLine(SourceLevels.Verbose, String.Format("{0}:\r\n{1}", msg, Flatten(tr)), tag);
_ts.WriteLine(SourceLevels.Verbose, String.Format("{0}:\r\n{1}", msg, Misc.Flatten(tr)), tag);
}
}

Expand Down Expand Up @@ -129,7 +115,7 @@ public void D(string tag, string msg, Exception tr)
}

lock (_locker) {
_ts.WriteLine(SourceLevels.ActivityTracing, String.Format("{0}:\r\n{1}", msg, Flatten(tr)), tag);
_ts.WriteLine(SourceLevels.ActivityTracing, String.Format("{0}:\r\n{1}", msg, Misc.Flatten(tr)), tag);
}
}

Expand All @@ -147,7 +133,7 @@ public void I(string tag, string msg, Exception tr)
}

lock (_locker) {
_ts.WriteLine(SourceLevels.Information, String.Format("{0}:\r\n{1}", msg, Flatten(tr)), tag);
_ts.WriteLine(SourceLevels.Information, String.Format("{0}:\r\n{1}", msg, Misc.Flatten(tr)), tag);
}
}

Expand All @@ -166,7 +152,7 @@ public void W(string tag, string msg)
public void W(string tag, Exception tr)
{
lock (_locker) {
_ts.WriteLine(Flatten(tr).Message, tag);
_ts.WriteLine(Misc.Flatten(tr).Message, tag);
}
}

Expand All @@ -177,7 +163,7 @@ public void W(string tag, string msg, Exception tr)
}

lock (_locker) {
_ts.WriteLine(SourceLevels.Warning, String.Format("{0}:\r\n{1}", msg, Flatten(tr)), tag);
_ts.WriteLine(SourceLevels.Warning, String.Format("{0}:\r\n{1}", msg, Misc.Flatten(tr)), tag);
}
}

Expand All @@ -200,7 +186,7 @@ public void E(string tag, string msg, Exception tr)
}

lock (_locker) {
_ts.Fail(String.Format("{0}: {1}", tag, msg), Flatten(tr).ToString());
_ts.Fail(String.Format("{0}: {1}", tag, msg), Misc.Flatten(tr).ToString());
}
}

Expand Down
10 changes: 0 additions & 10 deletions src/Couchbase.Lite.Shared/Util/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,6 @@ public static string ReplaceAll (this string str, string regex, string replaceme

return rgx.Replace (str, replacement);
}

public static Exception Flatten(this Exception e)
{
var ae = e as AggregateException;
if (ae == null) {
return e;
}

return ae.Flatten().InnerException;
}

public static long MillisecondsSinceEpoch(this DateTime dt)
{
Expand Down
10 changes: 10 additions & 0 deletions src/Couchbase.Lite.Shared/Util/Misc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ public static DateTime CreateDate(long milliSecondsSinceEpoch)
return Epoch.AddMilliseconds(milliSecondsSinceEpoch);
}

public static Exception Flatten(Exception inE)
{
var ae = inE as AggregateException;
if (ae == null) {
return inE;
}

return ae.Flatten().InnerException;
}

public static void SafeDispose<T>(ref T obj) where T : class, IDisposable
{
var tmp = obj;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static Task<HttpResponseMessage> HandleTransientErrors(Task<HttpResponseMessage>
return request;
}

var error = request.Exception.Flatten().InnerException;
var error = Misc.Flatten(request.Exception);

if (!Misc.IsTransientNetworkError(error) || strategy.RetriesRemaining == 0)
{
Expand Down

0 comments on commit a9ec1f5

Please sign in to comment.