Skip to content

Commit

Permalink
log: warning when import failed with message (#30)
Browse files Browse the repository at this point in the history
So that one can actually tell what happened, when an import failed
  • Loading branch information
wgnf authored Nov 7, 2021
1 parent f835628 commit b769c99
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/CsvProc9000.Model/Result.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@ public class Result<T>
{
public Result(
bool isSuccess,
T value = default)
T value = default,
string failureMessage = default)
{
IsSuccess = isSuccess;
Value = value;
FailureMessage = failureMessage ?? string.Empty;
}

public bool IsSuccess { get; }

public T Value { get; }

public string FailureMessage { get; }
}
}
4 changes: 2 additions & 2 deletions src/CsvProc9000/Csv/CsvImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public async Task<Result<CsvFile>> ImportAsync(
var file = await DoImportAsync(fileName, delimiter);
return new Result<CsvFile>(true, file);
}
catch (IOException)
catch (IOException ex)
{
return new Result<CsvFile>(false);
return new Result<CsvFile>(false, failureMessage: ex.Message);
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/CsvProc9000/Jobs/CsvProcessJobWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ private async Task<CsvFile> ImportFileAsync(CsvProcessJob job, Guid jobThreadId)

if (result.IsSuccess)
csvFile = result.Value;
else
_logger.LogWarning("T-{ThreadId} J-{JobId}# Import failed, because of '{Message}'. Retrying...",
jobThreadId, job.Id, result.FailureMessage);
}

return csvFile;
Expand Down

0 comments on commit b769c99

Please sign in to comment.