Skip to content

Commit

Permalink
Throwing errors if the sourcefile doesn't exist to avoid a nullpointe…
Browse files Browse the repository at this point in the history
…r when the Destination is using the reader.
  • Loading branch information
frederik5480 committed Jun 26, 2024
1 parent 3651429 commit d0bbac8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>10.0.16</Version>
<Version>10.0.17</Version>
<AssemblyVersion>1.0.0</AssemblyVersion>
<Title>Excel Provider</Title>
<Description>Excel Provider</Description>
Expand Down
16 changes: 10 additions & 6 deletions src/ExcelProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,18 +165,22 @@ void IDestination.SaveAsXml(XmlTextWriter xmlTextWriter)
{
if (!string.IsNullOrEmpty(WorkingDirectory))
{
return new ExcelSourceReader(GetSourceFilePath(), mapping, this);
var sourceFilePath = GetSourceFilePath();
if (!File.Exists(sourceFilePath))
throw new Exception($"Source file {SourceFile} does not exist - Working Directory {WorkingDirectory}");

return new ExcelSourceReader(sourceFilePath, mapping, this);
}
else
{
return new ExcelSourceReader(SourceFile, mapping, this);
if (!File.Exists(SourceFile))
throw new Exception($"Source file {SourceFile} does not exist - Working Directory {WorkingDirectory}");

return new ExcelSourceReader(SourceFile, mapping, this);
}
}
else
{
Logger?.Error("The file is not a Excel file");
return null;
}
throw new Exception("The file is not a Excel file");
}

public override void Close()
Expand Down

0 comments on commit d0bbac8

Please sign in to comment.