Skip to content

Commit

Permalink
Improve try/catching in Builder.cs
Browse files Browse the repository at this point in the history
If there is a SQL builder that fails, log the error and proceed anyway
  • Loading branch information
DDuarte committed Feb 19, 2017
1 parent 2331e6e commit 789f741
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
4 changes: 2 additions & 2 deletions WowPacketParser/Hotfix/HotfixStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static class HotfixStoreMgr
{
public static event Action<DB2Hash, int, bool> OnRecordReceived;

private static Dictionary<DB2Hash, IHotfixStore> _stores = new Dictionary<DB2Hash, IHotfixStore>();
private static readonly Dictionary<DB2Hash, IHotfixStore> _stores = new Dictionary<DB2Hash, IHotfixStore>();

public static IHotfixStore GetStore(DB2Hash hash)
{
Expand Down Expand Up @@ -81,4 +81,4 @@ public static void LoadStores(Assembly asm)
}
}
}
}
}
32 changes: 17 additions & 15 deletions WowPacketParser/SQL/Builder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,26 +97,27 @@ public static void DumpSQL(string prefix, string fileName, string header)
.Where(y => y.GetCustomAttributes().OfType<BuilderMethodAttribute>().Any())
.ToList();

var i = 0;
foreach (var method in builderMethods)
for (int i = 1; i <= builderMethods.Count; i++)
{
var method = builderMethods[i - 1];
var attr = method.GetCustomAttribute<BuilderMethodAttribute>();

if (attr.CheckVersionMismatch)
{
if (!((ClientVersion.Expansion == ClientType.WrathOfTheLichKing &&
Settings.TargetedDatabase == TargetedDatabase.WrathOfTheLichKing)
||
(ClientVersion.Expansion == ClientType.Cataclysm &&
Settings.TargetedDatabase == TargetedDatabase.Cataclysm)
||
(ClientVersion.Expansion == ClientType.WarlordsOfDraenor &&
Settings.TargetedDatabase == TargetedDatabase.WarlordsOfDraenor)
||
(ClientVersion.Expansion == ClientType.Legion &&
Settings.TargetedDatabase == TargetedDatabase.Legion)))
Settings.TargetedDatabase == TargetedDatabase.WrathOfTheLichKing)
||
(ClientVersion.Expansion == ClientType.Cataclysm &&
Settings.TargetedDatabase == TargetedDatabase.Cataclysm)
||
(ClientVersion.Expansion == ClientType.WarlordsOfDraenor &&
Settings.TargetedDatabase == TargetedDatabase.WarlordsOfDraenor)
||
(ClientVersion.Expansion == ClientType.Legion &&
Settings.TargetedDatabase == TargetedDatabase.Legion)))
{
Trace.WriteLine($"Error: Couldn't generate SQL output of {method.Name} since the targeted database and the sniff version don't match.");
Trace.WriteLine(
$"{i}/{builderMethods.Count} - Error: Couldn't generate SQL output of {method.Name} since the targeted database and the sniff version don't match.");
continue;
}
}
Expand All @@ -128,14 +129,15 @@ public static void DumpSQL(string prefix, string fileName, string header)
if (attr.Gameobjects)
parameters.Add(gameObjects);

Trace.WriteLine($"{++i}/{builderMethods.Count} - Write {method.Name}");
Trace.WriteLine($"{i}/{builderMethods.Count} - Write {method.Name}");
try
{
store.WriteData(method.Invoke(null, parameters.ToArray()).ToString());
}
catch (TargetInvocationException e)
{
ExceptionDispatchInfo.Capture(e.InnerException).Throw();
Trace.WriteLine($"{i}/{builderMethods.Count} - Error: Failed writing {method.Name}");
Trace.TraceError(e.InnerException?.ToString() ?? e.ToString());
}
}

Expand Down

0 comments on commit 789f741

Please sign in to comment.