Skip to content

Commit 8a992fd

Browse files
MalcolmnixonMalcolm Nixon
andauthored
Improve validation failure reports. (#65)
Co-authored-by: Malcolm Nixon <malcolm.nixon@hiarc.inc>
1 parent a2948a4 commit 8a992fd

24 files changed

+853
-77
lines changed

src/DemaConsulting.SpdxModel/SpdxAnnotation.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,19 +142,19 @@ public void Validate(string parent, List<string> issues)
142142
{
143143
// Validate Annotator Field
144144
if (Annotator.Length == 0)
145-
issues.Add($"{parent} Invalid Annotator Field");
145+
issues.Add($"{parent} Invalid Annotator Field - Empty");
146146

147147
// Validate Annotation Date Field
148148
if (!SpdxHelpers.IsValidSpdxDateTime(Date))
149-
issues.Add($"{parent} Invalid Annotation Date Field");
149+
issues.Add($"{parent} Invalid Annotation Date Field '{Date}'");
150150

151151
// Validate Annotation Type Field
152152
if (Type == SpdxAnnotationType.Missing)
153-
issues.Add($"{parent} Invalid Annotation Type Field");
153+
issues.Add($"{parent} Invalid Annotation Type Field - Missing");
154154

155155
// Validate Annotation Comment Field
156156
if (Comment.Length == 0)
157-
issues.Add($"{parent} Invalid Annotation Comment");
157+
issues.Add($"{parent} Invalid Annotation Comment - Empty");
158158
}
159159

160160
/// <summary>

src/DemaConsulting.SpdxModel/SpdxChecksum.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,17 @@ public static SpdxChecksum[] Enhance(SpdxChecksum[] array, SpdxChecksum[] others
115115
/// <summary>
116116
/// Perform validation of information
117117
/// </summary>
118-
/// <param name="fileName">Associated file name</param>
118+
/// <param name="parent">Associated parent node</param>
119119
/// <param name="issues">List to populate with issues</param>
120-
public void Validate(string fileName, List<string> issues)
120+
public void Validate(string parent, List<string> issues)
121121
{
122122
// Validate Algorithm Field
123123
if (Algorithm == SpdxChecksumAlgorithm.Missing)
124-
issues.Add($"File {fileName} Invalid Checksum Algorithm Field");
124+
issues.Add($"{parent} Invalid Checksum Algorithm Field - Missing");
125125

126126
// Validate Checksum Value Field
127127
if (Value.Length == 0)
128-
issues.Add($"File {fileName} Invalid Checksum Value Field");
128+
issues.Add($"{parent} Invalid Checksum Value Field - Empty");
129129
}
130130

131131
/// <summary>

src/DemaConsulting.SpdxModel/SpdxCreationInformation.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,21 +121,21 @@ public void Validate(List<string> issues)
121121
{
122122
// Validate Creator Field
123123
if (Creators.Length == 0)
124-
issues.Add("Document Invalid Creator Field");
124+
issues.Add("Document Invalid Creator Field - Empty");
125125

126126
// Validate Creators Field Entries
127127
foreach (var creator in Creators)
128128
if (!creator.StartsWith("Person:") &&
129129
!creator.StartsWith("Organization:") &&
130130
!creator.StartsWith("Tool:"))
131-
issues.Add($"Document Invalid Creator Entry: {creator}");
131+
issues.Add($"Document Invalid Creator Entry '{creator}'");
132132

133133
// Validate Created Field
134134
if (!SpdxHelpers.IsValidSpdxDateTime(Created))
135-
issues.Add("Document Invalid Created Field");
135+
issues.Add($"Document Invalid Created Field '{Created}'");
136136

137137
// Validate License List Version Field
138138
if (!string.IsNullOrEmpty(LicenseListVersion) && !LicenseListVersionRegex.IsMatch(LicenseListVersion))
139-
issues.Add("Document Invalid License List Version Field");
139+
issues.Add($"Document Invalid License List Version Field '{LicenseListVersion}'");
140140
}
141141
}

src/DemaConsulting.SpdxModel/SpdxDocument.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,23 +177,23 @@ public void Validate(List<string> issues, bool ntia = false)
177177
{
178178
// Validate SPDX Identifier Field
179179
if (Id != "SPDXRef-DOCUMENT")
180-
issues.Add("Document Invalid SPDX Identifier Field");
180+
issues.Add($"Document Invalid SPDX Identifier Field '{Id}'");
181181

182182
// Validate Document Name Field
183183
if (Name.Length == 0)
184-
issues.Add("Document Invalid Document Name Field");
184+
issues.Add("Document Invalid Document Name Field - Empty");
185185

186186
// Validate SPDX Version Field
187187
if (!VersionRegex.IsMatch(Version))
188-
issues.Add("Document Invalid SPDX Version Field");
188+
issues.Add($"Document Invalid SPDX Version Field '{Version}'");
189189

190190
// Validate Data License Field
191191
if (DataLicense != "CC0-1.0")
192-
issues.Add("Document Invalid Data License Field");
192+
issues.Add($"Document Invalid Data License Field '{DataLicense}'");
193193

194194
// Validate SPDX Document Namespace Field
195195
if (DocumentNamespace.Length == 0)
196-
issues.Add("Document Invalid SPDX Document Namespace Field");
196+
issues.Add("Document Invalid SPDX Document Namespace Field - Empty");
197197

198198
// Validate Creation Information
199199
CreationInformation.Validate(issues);
@@ -225,7 +225,7 @@ public void Validate(List<string> issues, bool ntia = false)
225225
// Check for duplicate elements
226226
var elements = GetAllElements().GroupBy(e => e.Id).Where(g => g.Count() > 1);
227227
foreach (var element in elements.Where(e => !string.IsNullOrWhiteSpace(e.Key)))
228-
issues.Add($"Document Duplicate Element ID: {element.Key}");
228+
issues.Add($"Document Duplicate Element ID '{element.Key}'");
229229

230230
// SPDX NTIA Relationship Check
231231
if (ntia && GetRootPackages().Length == 0)

src/DemaConsulting.SpdxModel/SpdxExternalDocumentReference.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,14 @@ public void Validate(List<string> issues)
124124
{
125125
// Validate External Document ID Field
126126
if (ExternalDocumentId.Length == 0)
127-
issues.Add("External Document Reference Invalid External Document ID Field");
127+
issues.Add("External Document Reference Invalid External Document ID Field - Empty");
128128

129129
// Validate External Document Checksum Field
130-
Checksum.Validate($"External Document Reference {ExternalDocumentId}", issues);
130+
Checksum.Validate($"External Document Reference '{ExternalDocumentId}'", issues);
131131

132132
// Validate SPDX Document URI Field
133133
if (Document.Length == 0)
134-
issues.Add($"External Document Reference {ExternalDocumentId} Invalid SPDX Document URI Field");
134+
issues.Add($"External Document Reference '{ExternalDocumentId}' Invalid SPDX Document URI Field - Empty");
135135
}
136136

137137
/// <summary>

src/DemaConsulting.SpdxModel/SpdxExternalReference.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,15 @@ public void Validate(string package, List<string> issues)
144144
{
145145
// Validate External Reference Category Field
146146
if (Category == SpdxReferenceCategory.Missing)
147-
issues.Add($"Package {package} Invalid External Reference Category Field");
147+
issues.Add($"Package '{package}' Invalid External Reference Category Field - Missing");
148148

149149
// Validate External Reference Type Field
150150
if (Type.Length == 0)
151-
issues.Add($"Package {package} Invalid External Reference Type Field");
151+
issues.Add($"Package '{package}' Invalid External Reference Type Field - Empty");
152152

153153
// Validate External Reference Locator Field
154154
if (Locator.Length == 0)
155-
issues.Add($"Package {package} Invalid External Reference Locator Field");
155+
issues.Add($"Package '{package}' Invalid External Reference Locator Field - Empty");
156156
}
157157

158158
/// <summary>

src/DemaConsulting.SpdxModel/SpdxExtractedLicensingInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,11 @@ public void Validate(List<string> issues)
147147
{
148148
// Validate Extracted License ID ID Field
149149
if (LicenseId.Length == 0)
150-
issues.Add("Extracted License Information Invalid License ID Field");
150+
issues.Add("Extracted License Information Invalid License ID Field - Empty");
151151

152152
// Validate Extracted Text Field
153153
if (ExtractedText.Length == 0)
154-
issues.Add($"Extracted License Information {LicenseId} Invalid Extracted Text Field");
154+
issues.Add($"Extracted License Information '{LicenseId}' Invalid Extracted Text Field - Empty");
155155
}
156156

157157
/// <summary>

src/DemaConsulting.SpdxModel/SpdxFile.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,21 +187,21 @@ public void Validate(List<string> issues)
187187
{
188188
// Validate File Name Field
189189
if (!FileName.StartsWith("./"))
190-
issues.Add($"File {FileName} Invalid File Name Field");
190+
issues.Add($"File '{FileName}' Invalid File Name Field");
191191

192192
// Validate File SPDX Identifier Field
193193
if (!SpdxRefRegex.IsMatch(Id))
194-
issues.Add($"File {FileName} Invalid SPDX Identifier Field");
194+
issues.Add($"File '{FileName}' Invalid SPDX Identifier Field '{Id}'");
195195

196196
// Validate Checksums
197197
if (!Array.Exists(Checksums, c => c.Algorithm == SpdxChecksumAlgorithm.Sha1))
198-
issues.Add($"File {FileName} Invalid Checksum Field (missing SHA1)");
198+
issues.Add($"File '{FileName}' Invalid Checksum Field (missing SHA1)");
199199
foreach (var checksum in Checksums)
200-
checksum.Validate(FileName, issues);
200+
checksum.Validate($"File '{FileName}'", issues);
201201

202202
// Validate Annotations
203203
foreach (var annotation in Annotations)
204-
annotation.Validate($"File {FileName}", issues);
204+
annotation.Validate($"File '{FileName}'", issues);
205205
}
206206

207207
/// <summary>

src/DemaConsulting.SpdxModel/SpdxPackage.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -383,64 +383,64 @@ public void Validate(List<string> issues, SpdxDocument? doc, bool ntia = false)
383383
{
384384
// Validate Package Name Field
385385
if (Name.Length == 0)
386-
issues.Add("Package Invalid Package Name Field");
386+
issues.Add("Package Invalid Package Name Field - Empty");
387387

388388
// SPDX NTIA Unique Identifier Check
389389
if (!SpdxRefRegex.IsMatch(Id))
390-
issues.Add($"Package {Name} Invalid SPDX Identifier Field");
390+
issues.Add($"Package '{Name}' Invalid SPDX Identifier Field '{Id}'");
391391

392392
// Validate Package Download Location Field
393393
if (DownloadLocation.Length == 0)
394-
issues.Add($"Package {Name} Invalid Package Download Location Field");
394+
issues.Add($"Package '{Name}' Invalid Package Download Location Field - Empty");
395395

396396
// Validate Package Supplier Field
397397
if (Supplier != null &&
398398
Supplier != NoAssertion &&
399399
!Supplier.StartsWith("Person:") &&
400400
!Supplier.StartsWith("Organization:"))
401-
issues.Add($"Package {Name} Invalid Package Supplier Field");
401+
issues.Add($"Package '{Name}' Invalid Package Supplier Field '{Supplier}'");
402402

403403
// Validate Package Originator Field
404404
if (Originator != null &&
405405
Originator != NoAssertion &&
406406
!Originator.StartsWith("Person:") &&
407407
!Originator.StartsWith("Organization:"))
408-
issues.Add($"Package {Name} Invalid Package Originator Field");
408+
issues.Add($"Package '{Name}' Invalid Package Originator Field '{Originator}'");
409409

410410
// Validate verification code
411411
VerificationCode?.Validate(Name, issues);
412412

413413
// Validate checksums
414414
foreach (var checksum in Checksums)
415-
checksum.Validate($"Package {Name}", issues);
415+
checksum.Validate($"Package '{Name}'", issues);
416416

417417
// Validate external references
418418
foreach (var externalReference in ExternalReferences)
419419
externalReference.Validate(Name, issues);
420420

421421
// If the document is provided then ensure all referenced files exist
422422
if (doc != null && Array.Exists(HasFiles, file => Array.TrueForAll(doc.Files, df => df.Id != file)))
423-
issues.Add($"Package {Name} HasFiles references missing files");
423+
issues.Add($"Package '{Name}' HasFiles references missing files");
424424

425425
// SPDX NTIA Supplier Name Check
426426
if (ntia && string.IsNullOrEmpty(Supplier))
427-
issues.Add($"NTIA: Package {Name} Missing Supplier");
427+
issues.Add($"NTIA: Package '{Name}' Missing Supplier");
428428

429429
// SPDX NTIA Version String Check
430430
if (ntia && string.IsNullOrEmpty(Version))
431-
issues.Add($"NTIA: Package {Name} Missing Version");
431+
issues.Add($"NTIA: Package '{Name}' Missing Version");
432432

433433
// Release Date field
434434
if (!SpdxHelpers.IsValidSpdxDateTime(ReleaseDate))
435-
issues.Add($"Package {Name} Invalid Release Date Field");
435+
issues.Add($"Package '{Name}' Invalid Release Date Field '{ReleaseDate}'");
436436

437437
// Built Date field
438438
if (!SpdxHelpers.IsValidSpdxDateTime(BuiltDate))
439-
issues.Add($"Package {Name} Invalid Built Date Field");
439+
issues.Add($"Package '{Name}' Invalid Built Date Field '{BuiltDate}'");
440440

441441
// Valid Until Date field
442442
if (!SpdxHelpers.IsValidSpdxDateTime(ValidUntilDate))
443-
issues.Add($"Package {Name} Invalid Valid Until Date Field");
443+
issues.Add($"Package '{Name}' Invalid Valid Until Date Field '{ValidUntilDate}'");
444444
}
445445

446446
/// <summary>

src/DemaConsulting.SpdxModel/SpdxPackageVerificationCode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public void Validate(string package, List<string> issues)
9797
{
9898
// Validate Package Verification Code Value Field
9999
if (Value.Length != 40)
100-
issues.Add($"Package {package} Invalid Package Verification Code Value");
100+
issues.Add($"Package '{package}' Invalid Package Verification Code Value '{Value}'");
101101
}
102102

103103
/// <summary>

0 commit comments

Comments
 (0)