Skip to content

Commit

Permalink
fix(HandlerChecker): log errors and improve message
Browse files Browse the repository at this point in the history
  • Loading branch information
MingboPeng committed May 15, 2023
1 parent 6fabb92 commit 73c6b5c
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/PollinationSDK/Helper/HandlerChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,36 @@ public object CheckWithHandlers(object inputData, List<IOAliasHandler> handlers)
object checkedData = null;
foreach (var item in handlers)
{
Exception err = null;
//Exception err = null;
try
{
handled = CheckWithHandler(inputData, item, out var newData);
checkedData = newData;
}
catch (Exception e)
{
err = e;
Helper.Logger?.Error(e, $"PollinationSDK: error.");
errors.Add($"Handler-{item.Language}-{item.Function}: {e}");
//throw;
}

if (err == null)
break;

errors.Add($"Handler-{item.Language}: {err.Message}");
}

if (handled)
if (errors.Any())
{
// throw exception
var joinedMessage = string.Join(Environment.NewLine, errors);
throw new ArgumentException(joinedMessage);
}
else if (handled)
{
return checkedData;
}
else
{
return inputData;
}


// throw exception
var joinedMessage = string.Join(Environment.NewLine, errors);
throw new ArgumentException(joinedMessage);


// local method
bool CheckWithHandler(object inData, IOAliasHandler handler, out object handledData)
Expand Down Expand Up @@ -152,6 +156,7 @@ private static Assembly LoadDll(string csProjName)
}
catch (Exception ex)
{
Helper.Logger?.Error(ex, $"PollinationSDK: cannot find handler libraries.");
throw new System.IO.FileNotFoundException($"Cannot find handler libraries.\n{ex.Message}");
}
}
Expand Down

0 comments on commit 73c6b5c

Please sign in to comment.