Skip to content

Commit

Permalink
fixed exception handling
Browse files Browse the repository at this point in the history
looking at BaseException to decide on how to handle
raising Input- and LiftiExceptions as probably validation errors related to the Query, removing message prefixes from wrapping AggregateExceptions from them
  • Loading branch information
h0lg committed Oct 25, 2024
1 parent 27470f9 commit d3f9f39
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions SubTubular/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Runtime.InteropServices;
using CommandLine;
using CommandLine.Text;
using Lifti;

namespace SubTubular;

Expand Down Expand Up @@ -88,15 +89,22 @@ await parserResult.WithParsedAsync<Release>(async release =>
return h;
})));
}
catch (InputException ex) { Console.Error.WriteLine(ex.Message); }
catch (HttpRequestException ex)
catch (Exception ex)
{
Console.Error.WriteLine("An unexpected error occurred loading data from YouTube."
+ " Try again later or with an updated version. " + ex.Message);
var cause = ex.GetBaseException();

if (cause is InputException || cause is LiftiException)
{
Console.Error.WriteLine(cause.Message);
return;
}

if (cause is HttpRequestException)
Console.Error.WriteLine("An unexpected error occurred loading data from YouTube."
+ " Try again later or with an updated version. " + cause.Message);

await WriteErrorLogAsync(originalCommand, ex.ToString());
}
catch (Exception ex) { await WriteErrorLogAsync(originalCommand, ex.ToString()); }
}

private static async Task SearchAsync(SearchCommand command, string originalCommand,
Expand Down

0 comments on commit d3f9f39

Please sign in to comment.