Skip to content

Commit af3e342

Browse files
committed
feat: add null checks for ejsData and function parameters
1 parent 548252e commit af3e342

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

OsmoDoc/Pdf/PdfDocumentGenerator.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,21 @@ public async static Task GeneratePdf(string templatePath, List<ContentMetaData>
2424
{
2525
try
2626
{
27+
if (metaDataList is null)
28+
{
29+
throw new ArgumentNullException(nameof(metaDataList));
30+
}
31+
32+
if (string.IsNullOrWhiteSpace(templatePath))
33+
{
34+
throw new ArgumentNullException(nameof(templatePath));
35+
}
36+
37+
if (string.IsNullOrWhiteSpace(outputFilePath))
38+
{
39+
throw new ArgumentNullException(nameof(outputFilePath));
40+
}
41+
2742
if (string.IsNullOrWhiteSpace(OsmoDocPdfConfig.WkhtmltopdfPath) && !RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
2843
{
2944
throw new Exception("WkhtmltopdfPath is not set in OsmoDocPdfConfig.");
@@ -180,7 +195,8 @@ private async static Task<string> ConvertEjsToHTML(string ejsFilePath, string ou
180195

181196
// Write json data string to json file
182197
string ejsDataJsonFilePath = Path.Combine(tempDirectoryFilePath, "ejsData.json");
183-
File.WriteAllText(ejsDataJsonFilePath, ejsDataJson);
198+
string contentToWrite = ejsDataJson ?? "{}";
199+
File.WriteAllText(ejsDataJsonFilePath, contentToWrite);
184200

185201
string commandLine = "cmd.exe";
186202
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))

0 commit comments

Comments
 (0)