Skip to content

Commit 1b3c37d

Browse files
committed
Misc exception messages improved (AE, ANE, IOE), ensured stack trace not cut off
1 parent e6d2a65 commit 1b3c37d

12 files changed

Lines changed: 21 additions & 17 deletions

File tree

Simple.Data.Ado/AdoAdapterGetter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public AdoAdapterGetter(AdoAdapter adapter, IDbTransaction transaction)
3535
public Func<object[],IDictionary<string,object>> CreateGetDelegate(string tableName, params object[] keyValues)
3636
{
3737
var primaryKey = _adapter.GetSchema().FindTable(tableName).PrimaryKey;
38-
if (primaryKey == null) throw new InvalidOperationException("Table has no primary key.");
38+
if (primaryKey == null) throw new InvalidOperationException(string.Format("Table '{0}' has no primary key.", tableName));
3939
if (primaryKey.Length != keyValues.Length) throw new ArgumentException("Incorrect number of values for key.");
4040

4141

@@ -107,7 +107,7 @@ private static object FixObjectType(object value)
107107
public IDictionary<string, object> Get(string tableName, object[] parameterValues)
108108
{
109109
var primaryKey = _adapter.GetSchema().FindTable(tableName).PrimaryKey;
110-
if (primaryKey == null) throw new InvalidOperationException("Table has no primary key.");
110+
if (primaryKey == null) throw new InvalidOperationException(string.Format("Table '{0}' has no primary key.", tableName));
111111
if (primaryKey.Length != parameterValues.Length) throw new ArgumentException("Incorrect number of values for key.");
112112

113113

Simple.Data.Ado/AdoAdapterQueryRunner.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ out IEnumerable<SimpleQueryClauseBase>
8383
{
8484
withCountClause = query.Clauses.OfType<WithCountClause>().First();
8585
}
86-
catch (InvalidOperationException)
86+
catch (InvalidOperationException e)
8787
{
8888
// Rethrow with meaning.
89-
throw new InvalidOperationException("No WithCountClause specified.");
89+
throw new InvalidOperationException("No WithCountClause specified.", e);
9090
}
9191

9292
query = query.ClearWithTotalCount();

Simple.Data.Ado/ProviderHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ private static string GetFileExtension(string filename)
6868
{
6969
var extension = Path.GetExtension(filename);
7070

71-
if (extension == null) throw new ArgumentException("Unrecognised file.");
71+
if (extension == null) throw new ArgumentException(string.Format("Unrecognised file name '{0}': no extension.", filename), "filename");
7272
return extension.TrimStart('.').ToLower();
7373
}
7474

@@ -111,7 +111,7 @@ private static IConnectionProvider LoadProviderByConnectionToken(ConnectionToken
111111
provider = ComposeProvider(token.ProviderName);
112112
if (provider == null)
113113
{
114-
throw new InvalidOperationException("Provider could not be resolved.");
114+
throw new InvalidOperationException(string.Format("Provider '{0}' could not be resolved.", token.ProviderName));
115115
}
116116

117117
provider.SetConnectionString(token.ConnectionString);

Simple.Data.Ado/Schema/DatabaseSchema.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public ObjectName BuildObjectName(String text)
139139
if (text == null) throw new ArgumentNullException("text");
140140
if (!text.Contains('.')) return new ObjectName(this.DefaultSchema, text);
141141
var schemaDotTable = text.Split('.');
142-
if (schemaDotTable.Length != 2) throw new InvalidOperationException("Could not parse table name.");
142+
if (schemaDotTable.Length != 2) throw new InvalidOperationException(string.Format("Could not parse table name '{0}'.", text));
143143
return new ObjectName(schemaDotTable[0], schemaDotTable[1]);
144144
}
145145

Simple.Data.Ado/Schema/ProcedureCollection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ private Procedure FindImpl(string procedureName)
5656
if (procedureName.Contains('.'))
5757
{
5858
var schemaDotprocedure = procedureName.Split('.');
59-
if (schemaDotprocedure.Length != 2) throw new InvalidOperationException("Could not resolve qualified procedure name.");
59+
if (schemaDotprocedure.Length != 2) throw new InvalidOperationException(string.Format("Could not resolve qualified procedure name '{0}'.", procedureName));
6060
return Find(schemaDotprocedure[1], schemaDotprocedure[0]);
6161
}
6262
if (!string.IsNullOrWhiteSpace(_defaultSchema))

Simple.Data.Ado/SimpleReferenceFormatter.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System.ComponentModel;
2+
13
namespace Simple.Data.Ado
24
{
35
using System;
@@ -99,7 +101,7 @@ private string MathOperatorToString(MathOperator @operator)
99101
case MathOperator.Modulo:
100102
return _schema.Operators.Modulo;
101103
default:
102-
throw new InvalidOperationException("Invalid MathOperator specified.");
104+
throw new InvalidEnumArgumentException("Invalid MathOperator specified.");
103105
}
104106
}
105107

Simple.Data.Mocking/Ado/MockSchemaProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public string QuoteObjectName(string unquotedName)
145145
public string NameParameter(string baseName)
146146
{
147147
if (baseName == null) throw new ArgumentNullException("baseName");
148-
if (baseName.Length == 0) throw new ArgumentException("Base name must be provided");
148+
if (baseName.Length == 0) throw new ArgumentException("Base name must be provided", "baseName");
149149
return (baseName.StartsWith("@")) ? baseName : "@" + baseName;
150150
}
151151

Simple.Data.SqlCe40/SqlCe40SchemaProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public string QuoteObjectName(string unquotedName)
112112
public string NameParameter(string baseName)
113113
{
114114
if (baseName == null) throw new ArgumentNullException("baseName");
115-
if (baseName.Length == 0) throw new ArgumentException("Base name must be provided");
115+
if (baseName.Length == 0) throw new ArgumentException("Base name must be provided", "baseName");
116116
return (baseName.StartsWith("@")) ? baseName : "@" + baseName;
117117
}
118118

Simple.Data.SqlServer/SqlSchemaProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public string QuoteObjectName(string unquotedName)
150150
public string NameParameter(string baseName)
151151
{
152152
if (baseName == null) throw new ArgumentNullException("baseName");
153-
if (baseName.Length == 0) throw new ArgumentException("Base name must be provided");
153+
if (baseName.Length == 0) throw new ArgumentException("Base name must be provided", "baseName");
154154
return (baseName.StartsWith("@")) ? baseName : "@" + baseName;
155155
}
156156

Simple.Data/InMemoryAdapter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ public bool IsValidFunction(string functionName)
373373

374374
public IEnumerable<IEnumerable<IEnumerable<KeyValuePair<string, object>>>> Execute(string functionName, IDictionary<string, object> parameters)
375375
{
376-
if (!_functions.ContainsKey(functionName)) throw new InvalidOperationException("No function found with that name.");
376+
if (!_functions.ContainsKey(functionName)) throw new InvalidOperationException(string.Format("Function '{0}' not found.", functionName));
377377
var obj = _functions[functionName].DynamicInvoke(parameters.Values.ToArray());
378378

379379
var dict = obj as IDictionary<string, object>;

0 commit comments

Comments
 (0)