-
Notifications
You must be signed in to change notification settings - Fork 648
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ConnectionStringParser swallows stack trace
the catch was redundant. the message can be derived from the stack trace also it did not add the inner exception which would obscure the debugging experience
- Loading branch information
1 parent
d41c13e
commit f3d93a4
Showing
1 changed file
with
18 additions
and
23 deletions.
There are no files selected for viewing
41 changes: 18 additions & 23 deletions
41
src/RabbitMQ/NServiceBus.RabbitMQ/Config/ConnectionStringParser.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,38 @@ | ||
using IHostConfiguration = EasyNetQ.IHostConfiguration; | ||
|
||
namespace NServiceBus.Transports.RabbitMQ.Config | ||
namespace NServiceBus.Transports.RabbitMQ.Config | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Data.Common; | ||
using System.Text.RegularExpressions; | ||
using EasyNetQ; | ||
using System.Linq; | ||
|
||
public class ConnectionStringParser : DbConnectionStringBuilder, IConnectionStringParser | ||
{ | ||
ConnectionConfiguration connectionConfiguration; | ||
|
||
public IConnectionConfiguration Parse(string connectionString) | ||
{ | ||
ConnectionString = connectionString; | ||
|
||
try | ||
{ | ||
connectionConfiguration = new ConnectionConfiguration(); | ||
|
||
foreach(var pair in | ||
(from property in typeof(ConnectionConfiguration).GetProperties() | ||
let match = Regex.Match(connectionString, string.Format("[^\\w]*{0}=(?<{0}>[^;]+)", property.Name), RegexOptions.IgnoreCase) | ||
where match.Success | ||
select new { Property = property, match.Groups[property.Name].Value })) | ||
pair.Property.SetValue(connectionConfiguration, TypeDescriptor.GetConverter(pair.Property.PropertyType).ConvertFromString(pair.Value),null); | ||
connectionConfiguration = new ConnectionConfiguration(); | ||
|
||
if (ContainsKey("host")) | ||
connectionConfiguration.ParseHosts(this["host"] as string); | ||
foreach (var pair in | ||
(from property in typeof(ConnectionConfiguration).GetProperties() | ||
let match = Regex.Match(connectionString, string.Format("[^\\w]*{0}=(?<{0}>[^;]+)", property.Name), RegexOptions.IgnoreCase) | ||
where match.Success | ||
select new | ||
{ | ||
Property = property, | ||
match.Groups[property.Name].Value | ||
})) | ||
pair.Property.SetValue(connectionConfiguration, TypeDescriptor.GetConverter(pair.Property.PropertyType).ConvertFromString(pair.Value), null); | ||
|
||
connectionConfiguration.Validate(); | ||
return connectionConfiguration; | ||
} | ||
catch (Exception parseException) | ||
if (ContainsKey("host")) | ||
{ | ||
throw new Exception(string.Format("Connection String parsing exception {0}", parseException.Message)); | ||
connectionConfiguration.ParseHosts(this["host"] as string); | ||
} | ||
|
||
connectionConfiguration.Validate(); | ||
return connectionConfiguration; | ||
} | ||
} | ||
} |