Skip to content

Commit

Permalink
Improve error handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianStehle committed Jun 23, 2022
1 parent 624a147 commit da5ba2d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static async Task DoVersionedAsync(this ILogger log, string process, long
}
catch (Exception ex)
{
HandleException(ex, log.StepFailed);
log.StepFailed(ex);
}
finally
{
Expand All @@ -54,7 +54,7 @@ public static async Task DoSafeAsync(this ILogger log, string process, Func<Task
}
catch (Exception ex)
{
HandleException(ex, log.StepFailed);
log.StepFailed(ex);
}
finally
{
Expand All @@ -68,7 +68,6 @@ public static void ProcessSkipped(this ILogger log, string process, string reaso
try
{
log.StepStart(process);

log.StepSkipped(reason);
}
finally
Expand All @@ -83,7 +82,6 @@ public static void ProcessCompleted(this ILogger log, string process)
try
{
log.StepStart(process);

log.StepSuccess();
}
finally
Expand All @@ -98,15 +96,33 @@ public static void ProcessFailed(this ILogger log, string process, Exception exc
try
{
log.StepStart(process);
log.StepFailed(exception);
}
finally
{
LockObject.Release();
}
}

HandleException(exception, log.StepFailed);
public static void ProcessFailed(this ILogger log, string process, string error)
{
LockObject.Wait();
try
{
log.StepStart(process);
log.StepFailed(error);
}
finally
{
LockObject.Release();
}
}

public static void StepFailed(this ILogger log, Exception ex)
{
HandleException(ex, log.StepFailed);
}

public static void HandleException(Exception ex, Action<string> error)
{
switch (ex)
Expand All @@ -129,6 +145,12 @@ public static void HandleException(Exception ex, Action<string> error)
break;
}

case FileNotFoundException ex5:
{
error(ex5.Message);
break;
}

case { } ex3:
{
error(ex3.ToString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ public UploadPipeline(ISession session, ILogger log, IFileSystem fs)
log.ProcessCompleted(process);
}
}
catch (FileNotFoundException)
{
log.ProcessFailed(process, "File not found.");
}
catch (Exception ex)
{
log.ProcessFailed(process, ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public sealed class InheritanceProcessor : ISchemaProcessor
{
public void Process(SchemaProcessorContext context)
{
var discriminator = GetDiscriminator(context.Type);
var discriminator = GetDiscriminator(context.ContextualType);

if (discriminator != null)
{
Expand Down

0 comments on commit da5ba2d

Please sign in to comment.