Skip to content

Commit

Permalink
ConnectionStringParser swallows stack trace
Browse files Browse the repository at this point in the history
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
SimonCropp committed Aug 19, 2013
1 parent d41c13e commit f3d93a4
Showing 1 changed file with 18 additions and 23 deletions.
41 changes: 18 additions & 23 deletions src/RabbitMQ/NServiceBus.RabbitMQ/Config/ConnectionStringParser.cs
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;
}
}
}

0 comments on commit f3d93a4

Please sign in to comment.