Commit 1305424b authored by Marc Gravell's avatar Marc Gravell

include libver in exceptions, because I'm tired of asking for it

parent b963ec8a
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Reflection;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
...@@ -146,7 +147,7 @@ internal static Exception PopulateInnerExceptions(ReadOnlySpan<ServerEndPoint> s ...@@ -146,7 +147,7 @@ internal static Exception PopulateInnerExceptions(ReadOnlySpan<ServerEndPoint> s
{ {
return innerExceptions[0]; return innerExceptions[0];
} }
else if(innerExceptions.Count > 1) else if (innerExceptions.Count > 1)
{ {
return new AggregateException(innerExceptions); return new AggregateException(innerExceptions);
} }
...@@ -167,6 +168,17 @@ internal static Exception NoCursor(RedisCommand command) ...@@ -167,6 +168,17 @@ internal static Exception NoCursor(RedisCommand command)
return new RedisCommandException("Command cannot be used with a cursor: " + s); return new RedisCommandException("Command cannot be used with a cursor: " + s);
} }
private static string _libVersion;
internal static string GetLibVersion()
{
if (_libVersion == null)
{
var assembly = typeof(ConnectionMultiplexer).Assembly;
_libVersion = ((AssemblyFileVersionAttribute)Attribute.GetCustomAttribute(assembly, typeof(AssemblyFileVersionAttribute)))?.Version
?? assembly.GetName().Version.ToString();
}
return _libVersion;
}
internal static Exception Timeout(ConnectionMultiplexer mutiplexer, string baseErrorMessage, Message message, ServerEndPoint server) internal static Exception Timeout(ConnectionMultiplexer mutiplexer, string baseErrorMessage, Message message, ServerEndPoint server)
{ {
List<Tuple<string, string>> data = new List<Tuple<string, string>> { Tuple.Create("Message", message.CommandAndKey) }; List<Tuple<string, string>> data = new List<Tuple<string, string>> { Tuple.Create("Message", message.CommandAndKey) };
...@@ -188,13 +200,13 @@ void add(string lk, string sk, string v) ...@@ -188,13 +200,13 @@ void add(string lk, string sk, string v)
sb.Append(", ").Append(sk).Append(": ").Append(v); sb.Append(", ").Append(sk).Append(": ").Append(v);
} }
} }
add("Version", "v", GetLibVersion());
if (server != null) if (server != null)
{ {
server.GetOutstandingCount(message.Command, out int inst, out int qs, out int @in); server.GetOutstandingCount(message.Command, out int inst, out int qs, out int @in);
add("Instantaneous", "inst", inst.ToString()); add("Instantaneous", "inst", inst.ToString());
add("Queue-Awaiting-Response", "qs", qs.ToString()); add("Queue-Awaiting-Response", "qs", qs.ToString());
add("Inbound-Bytes", "in", @in.ToString()); if (@in >= 0) add("Inbound-Bytes", "in", @in.ToString());
if (mutiplexer.StormLogThreshold >= 0 && qs >= mutiplexer.StormLogThreshold && Interlocked.CompareExchange(ref mutiplexer.haveStormLog, 1, 0) == 0) if (mutiplexer.StormLogThreshold >= 0 && qs >= mutiplexer.StormLogThreshold && Interlocked.CompareExchange(ref mutiplexer.haveStormLog, 1, 0) == 0)
{ {
......
...@@ -328,6 +328,13 @@ public Task FlushAsync() ...@@ -328,6 +328,13 @@ public Task FlushAsync()
} }
var data = new List<Tuple<string, string>>(); var data = new List<Tuple<string, string>>();
void add(string lk, string sk, string v)
{
data.Add(Tuple.Create(lk, v));
exMessage.Append(", ").Append(sk).Append(": ").Append(v);
}
add("Version", "v", ExceptionFactory.GetLibVersion());
if (IncludeDetailInExceptions) if (IncludeDetailInExceptions)
{ {
if (bridge != null) if (bridge != null)
...@@ -339,12 +346,6 @@ public Task FlushAsync() ...@@ -339,12 +346,6 @@ public Task FlushAsync()
data.Add(Tuple.Create("FailureType", failureType.ToString())); data.Add(Tuple.Create("FailureType", failureType.ToString()));
data.Add(Tuple.Create("EndPoint", Format.ToString(bridge.ServerEndPoint?.EndPoint))); data.Add(Tuple.Create("EndPoint", Format.ToString(bridge.ServerEndPoint?.EndPoint)));
void add(string lk, string sk, string v)
{
data.Add(Tuple.Create(lk, v));
exMessage.Append(", ").Append(sk).Append(": ").Append(v);
}
add("Origin", "origin", origin); add("Origin", "origin", origin);
// add("Input-Buffer", "input-buffer", _ioPipe.Input); // add("Input-Buffer", "input-buffer", _ioPipe.Input);
add("Outstanding-Responses", "outstanding", GetSentAwaitingResponseCount().ToString()); add("Outstanding-Responses", "outstanding", GetSentAwaitingResponseCount().ToString());
......
...@@ -799,9 +799,8 @@ private RedisValue Simplify() ...@@ -799,9 +799,8 @@ private RedisValue Simplify()
} }
/// <summary> /// <summary>
/// Convert to a long if possible, returning true. /// <para>Convert to a long if possible, returning true.</para>
/// /// <para>Returns false otherwise.</para>
/// Returns false otherwise.
/// </summary> /// </summary>
/// <param name="val">The <see cref="long"/> value, if conversion was possible.</param> /// <param name="val">The <see cref="long"/> value, if conversion was possible.</param>
public bool TryParse(out long val) public bool TryParse(out long val)
...@@ -830,9 +829,8 @@ public bool TryParse(out long val) ...@@ -830,9 +829,8 @@ public bool TryParse(out long val)
} }
/// <summary> /// <summary>
/// Convert to a int if possible, returning true. /// <para>Convert to a int if possible, returning true.</para>
/// /// <para>Returns false otherwise.</para>
/// Returns false otherwise.
/// </summary> /// </summary>
/// <param name="val">The <see cref="int"/> value, if conversion was possible.</param> /// <param name="val">The <see cref="int"/> value, if conversion was possible.</param>
public bool TryParse(out int val) public bool TryParse(out int val)
...@@ -848,9 +846,8 @@ public bool TryParse(out int val) ...@@ -848,9 +846,8 @@ public bool TryParse(out int val)
} }
/// <summary> /// <summary>
/// Convert to a double if possible, returning true. /// <para>Convert to a double if possible, returning true.</para>
/// /// <para>Returns false otherwise.</para>
/// Returns false otherwise.
/// </summary> /// </summary>
/// <param name="val">The <see cref="double"/> value, if conversion was possible.</param> /// <param name="val">The <see cref="double"/> value, if conversion was possible.</param>
public bool TryParse(out double val) public bool TryParse(out double val)
......
...@@ -21,6 +21,13 @@ public void NullLastException() ...@@ -21,6 +21,13 @@ public void NullLastException()
} }
} }
[Fact]
public void CanGetVersion()
{
var libVer = ExceptionFactory.GetLibVersion();
Assert.Matches(@"2\.[0-9]+\.[0-9]+\.[0-9]+", libVer);
}
[Fact] [Fact]
public void NullSnapshot() public void NullSnapshot()
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment