Skip to content

Commit a5824e2

Browse files
committed
Logging each exception msg to Debug.WriteLine before throwing. Simplifies error hunting at my current job ;-)
1 parent 9ede763 commit a5824e2

File tree

5 files changed

+32
-17
lines changed

5 files changed

+32
-17
lines changed

ObjectFiller/Filler.cs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections;
33
using System.Collections.Generic;
44
using System.Configuration;
5+
using System.Diagnostics;
56
using System.Globalization;
67
using System.Linq;
78
using System.Reflection;
@@ -109,8 +110,9 @@ private object CreateInstanceOfType(Type type, ObjectFillerSetup currentSetup)
109110

110111
if (constructorArgs.Count == 0)
111112
{
112-
throw new InvalidOperationException("Could not found a constructor for type [" + type.Name +
113-
"] where the parameters can be filled with the current objectfiller setup");
113+
var message = "Could not found a constructor for type [" + type.Name + "] where the parameters can be filled with the current objectfiller setup";
114+
Debug.WriteLine("ObjectFiller: " + message);
115+
throw new InvalidOperationException(message);
114116
}
115117
}
116118
}
@@ -302,13 +304,12 @@ private IDictionary GetFilledDictionary(Type propertyType, ObjectFillerSetup cur
302304

303305
if (dictionary.Contains(keyObject))
304306
{
305-
throw new ArgumentException(
306-
string.Format(
307-
"Generating Keyvalue failed because it generates always the same data for type [{0}]. Please check your setup.",
308-
keyType));
307+
string message = string.Format("Generating Keyvalue failed because it generates always the same data for type [{0}]. Please check your setup.", keyType);
308+
Debug.WriteLine("ObjectFiller: " + message);
309+
throw new ArgumentException(message);
309310
}
310311

311-
object valueObject = GetFilledObject(valueType, currentSetup);
312+
object valueObject = GetFilledObject(valueType, currentSetup);
312313
dictionary.Add(keyObject, valueObject);
313314
}
314315
return dictionary;
@@ -368,12 +369,12 @@ private object GetInterfaceInstance(Type interfaceType, ObjectFillerSetup setup)
368369
{
369370
if (setup.InterfaceMocker == null)
370371
{
371-
throw new InvalidOperationException(
372-
string.Format("ObjectFiller Interface mocker missing and type [{0}] not registered",
373-
interfaceType.Name));
372+
string message = string.Format("ObjectFiller Interface mocker missing and type [{0}] not registered", interfaceType.Name);
373+
Debug.WriteLine("ObjectFiller: " + message);
374+
throw new InvalidOperationException(message);
374375
}
375376

376-
MethodInfo method = setup.InterfaceMocker.GetType().GetMethod("Create");
377+
MethodInfo method = setup.InterfaceMocker.GetType().GetMethod("Create");
377378
MethodInfo genericMethod = method.MakeGenericMethod(new[] { interfaceType });
378379
result = genericMethod.Invoke(setup.InterfaceMocker, null);
379380
}
@@ -388,7 +389,9 @@ private object GetRandomValue(Type propertyType, ObjectFillerSetup setup)
388389
return setup.TypeToRandomFunc[propertyType]();
389390
}
390391

391-
throw new TypeInitializationException(propertyType.FullName, new Exception("The type [" + propertyType.Name + "] was not registered in the randomizer."));
392+
string message = "The type [" + propertyType.Name + "] was not registered in the randomizer.";
393+
Debug.WriteLine("ObjectFiller: " + message);
394+
throw new TypeInitializationException(propertyType.FullName, new Exception(message));
392395
}
393396

394397
private static bool TypeIsValidForObjectFiller(Type type, ObjectFillerSetup currentSetup)

ObjectFiller/Plugins/EnumeratorPlugin.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics;
34

45
namespace Tynamix.ObjectFiller
56
{
@@ -31,7 +32,9 @@ public T GetValue()
3132

3233
if (!hasNext)
3334
{
34-
throw new Exception("Unable to get next value from enumeration " + _enumerable);
35+
string message = "Unable to get next value from enumeration " + _enumerable;
36+
Debug.WriteLine("ObjectFiller: " + message);
37+
throw new Exception(message);
3538
}
3639
}
3740

ObjectFiller/Plugins/RandomListItem.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics;
34

45
namespace Tynamix.ObjectFiller
56
{
@@ -11,9 +12,11 @@ public RandomListItem(List<T> allAvailableValues)
1112
{
1213
if (allAvailableValues == null || allAvailableValues.Count == 0)
1314
{
14-
throw new ArgumentException("List in RandomListItem ranomizer can not be empty!");
15+
const string message = "List in RandomListItem ranomizer can not be empty!";
16+
Debug.WriteLine("ObjectFiller: " + message);
17+
throw new ArgumentException(message);
1518
}
16-
_allAvailableValues = allAvailableValues;
19+
_allAvailableValues = allAvailableValues;
1720

1821
}
1922

ObjectFiller/Plugins/String/PatternGenerator.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,9 @@ private static char NextChar(char charClass)
251251
if (charClass == 'A') return NextUpperCaseChar();
252252
if (charClass == 'N') return NextDecimalDigit();
253253
if (charClass == 'X') return NextHexDigit();
254+
255+
var message = "Unexpected character class: " + charClass;
256+
Debug.WriteLine("ObjectFiller: " + message);
254257
throw new InvalidOperationException();
255258
}
256259

ObjectFiller/Setup/FluentFillerApi.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics;
34
using System.Linq.Expressions;
45
using System.Reflection;
56

@@ -114,9 +115,11 @@ public FluentFillerApi<TTargetObject> SetInterfaceMocker(IInterfaceMocker mocker
114115
{
115116
if (SetupManager.GetFor<TTargetObject>().InterfaceMocker != null)
116117
{
117-
throw new ArgumentException("You can not set a interface mocker more than once!");
118+
const string message = "You can not set a interface mocker more than once!";
119+
Debug.WriteLine("ObjectFiller: " + message);
120+
throw new ArgumentException(message);
118121
}
119-
SetupManager.GetFor<TTargetObject>().InterfaceMocker = mocker;
122+
SetupManager.GetFor<TTargetObject>().InterfaceMocker = mocker;
120123
return this;
121124
}
122125

0 commit comments

Comments
 (0)