Skip to content

Commit 3073611

Browse files
committed
better error logging on the stupid built task
1 parent a25ccf1 commit 3073611

File tree

1 file changed

+43
-21
lines changed

1 file changed

+43
-21
lines changed

SER.csproj

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,10 @@
8080
<None Include="THIRD_PARTY_LICENSES.txt" CopyToOutputDirectory="Always" />
8181
</ItemGroup>
8282

83-
<!-- ignore warnings about mismatch between versions of core libs -->
83+
<!-- ignore warnings about mismatch between versions of core libs
84+
and unreachable code because compiler is stupid -->
8485
<PropertyGroup>
85-
<NoWarn>$(NoWarn);MSB3277</NoWarn>
86+
<NoWarn>$(NoWarn);MSB3277;CS0162</NoWarn>
8687
</PropertyGroup>
8788

8889
<!-- nuget refs -->
@@ -130,6 +131,7 @@
130131
<Using Namespace="System.Reflection" />
131132
<Code Type="Fragment" Language="cs">
132133
<![CDATA[
134+
#nullable enable annotations
133135
// 1. Resolver for SCP:SL Dependencies
134136
ResolveEventHandler resolver = (sender, args) => {
135137
try {
@@ -144,14 +146,18 @@
144146
return Assembly.LoadFrom(fullPath);
145147
}
146148
}
147-
catch { /* Safe verify, ignore errors */ }
149+
catch (Exception e)
150+
{
151+
Log.LogError("Resolver Error: " + e.ToString());
152+
}
153+
148154
return null;
149155
};
150156
157+
try
158+
{
151159
AppDomain.CurrentDomain.AssemblyResolve += resolver;
152160
153-
try
154-
{
155161
if (!File.Exists(AssemblyPath)) {
156162
Log.LogError("Target DLL not found: " + AssemblyPath);
157163
return false;
@@ -163,36 +169,42 @@
163169
164170
{
165171
// 4. Find the class (Namespace.ClassName)
166-
Type targetType = assembly.GetType("SER.Code.MethodSystem.MethodIndex");
172+
Type? targetType = assembly.GetType("SER.Code.MethodSystem.MethodIndex");
167173
if (targetType == null)
168174
{
169175
Log.LogError("Validation Error: Type 'SER.Code.MethodSystem.MethodIndex' not found.");
170176
return false;
171177
}
172178
173179
// 5. Find the method
174-
MethodInfo method = targetType.GetMethod("AddAllDefinedMethodsInAssembly", BindingFlags.Public | BindingFlags.Static);
180+
MethodInfo? method = targetType.GetMethod(
181+
"AddAllDefinedMethodsInAssembly",
182+
BindingFlags.Public | BindingFlags.Static
183+
);
175184
if (method == null)
176185
{
177186
Log.LogError("Validation Error: Static method 'AddAllDefinedMethodsInAssembly()' not found.");
178187
return false;
179188
}
180189
181-
method.Invoke(null, [assembly]);
190+
method.Invoke(null, new object[] { assembly });
182191
Log.LogMessage(MessageImportance.High, ">>> Loaded methods.");
183192
}
184193
185194
{
186195
// 4. Find the class (Namespace.ClassName)
187-
Type targetType = assembly.GetType("SER.Code.Examples.Example");
196+
Type? targetType = assembly.GetType("SER.Code.Examples.Example");
188197
if (targetType == null)
189198
{
190199
Log.LogError("Validation Error: Type 'SER.Code.Examples.Example' not found.");
191200
return false;
192201
}
193202
194203
// 5. Find the method
195-
MethodInfo method = targetType.GetMethod("Verify", BindingFlags.Public | BindingFlags.Static);
204+
MethodInfo? method = targetType.GetMethod(
205+
"Verify",
206+
BindingFlags.Public | BindingFlags.Static
207+
);
196208
if (method == null)
197209
{
198210
Log.LogError("Validation Error: Static method 'Verify()' not found.");
@@ -214,24 +226,34 @@
214226
return true;
215227
}
216228
}
217-
catch (Exception ex)
229+
catch (OperationCanceledException)
218230
{
219-
if (ex is ReflectionTypeLoadException re) {
220-
foreach (var loaderEx in re.LoaderExceptions) {
221-
Log.LogError("Loader Error: " + loaderEx.Message);
222-
}
223-
}
224-
else if (ex.InnerException != null) {
225-
Log.LogError("Runtime Error: " + ex.InnerException.Message);
226-
}
227-
else {
228-
Log.LogError("Task Error: " + ex.ToString());
231+
throw;
232+
}
233+
catch (ReflectionTypeLoadException re)
234+
{
235+
foreach (var loaderEx in re.LoaderExceptions)
236+
{
237+
Log.LogError("Loader Error: " + loaderEx.ToString());
229238
}
239+
return false;
240+
}
241+
catch (TargetInvocationException tie)
242+
{
243+
Log.LogError("Invocation Error: " +
244+
(tie.InnerException != null ? tie.InnerException.ToString() : tie.ToString()));
245+
return false;
246+
}
247+
catch (Exception ex)
248+
{
249+
Log.LogError("Task Error: " + ex.ToString());
250+
return false;
230251
}
231252
finally {
232253
// 7. Detach Resolver to keep build process clean
233254
AppDomain.CurrentDomain.AssemblyResolve -= resolver;
234255
}
256+
#nullable disable annotations
235257
]]>
236258
</Code>
237259
</Task>

0 commit comments

Comments
 (0)