Skip to content

Commit

Permalink
Removes wrapping error in benchmark and makes rule violation coordina…
Browse files Browse the repository at this point in the history
…tes nullable
  • Loading branch information
sakari-malkki committed Sep 12, 2024
1 parent b9b8327 commit a9967c0
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 16 deletions.
7 changes: 4 additions & 3 deletions Px.Utils.TestingApp/Commands/PxFileValidationBenchmark.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Px.Utils.PxFile.Metadata;
using Px.Utils.Exceptions;
using Px.Utils.PxFile.Metadata;
using Px.Utils.Validation;
using System.Text;

Expand Down Expand Up @@ -30,10 +31,10 @@ protected override void OneTimeBenchmarkSetup()
{
encoding = reader.GetEncoding(stream);
}
catch (Exception e)
catch (InvalidPxFileMetadataException)
{
Console.WriteLine($"Error while reading the encoding of the file: {e.Message}");
encoding = Encoding.Default;
throw;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private static Dictionary<KeyValuePair<string, string>, string[]> FindDimensionV
KeyValuePair<ValidationFeedbackKey, ValidationFeedbackValue> feedback = new(
new(ValidationFeedbackLevel.Error,
ValidationFeedbackRule.VariableValuesMissing),
new(filename, 0, 0, $"{dimension}, {language}")
new(filename, additionalInfo: $"{dimension}, {language}")
);

feedbackItems.Add(feedback);
Expand Down Expand Up @@ -98,7 +98,7 @@ private static Dictionary<KeyValuePair<string, string>, string[]> FindDimensionV
return new KeyValuePair<ValidationFeedbackKey, ValidationFeedbackValue> (
new(recommended ? ValidationFeedbackLevel.Warning : ValidationFeedbackLevel.Error,
recommended ? ValidationFeedbackRule.RecommendedKeyMissing : ValidationFeedbackRule.RequiredKeyMissing),
new(validator._filename, 0, 0, $"{keyword}, {language}, {dimensionName}, {dimensionValueName}")
new(validator._filename, additionalInfo: $"{keyword}, {language}, {dimensionName}, {dimensionValueName}")
);
}
else if (entry.Key.FirstSpecifier is null || entry.Key.SecondSpecifier is null)
Expand Down Expand Up @@ -143,7 +143,7 @@ private static Dictionary<KeyValuePair<string, string>, string[]> FindDimensionV
return new(
new(ValidationFeedbackLevel.Warning,
ValidationFeedbackRule.RecommendedKeyMissing),
new(validator._filename, 0, 0, $"{keyword}, {language}, {dimensionName}")
new(validator._filename, additionalInfo: $"{keyword}, {language}, {dimensionName}")
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ validator._headingDimensionNames is not null &&

feedbackItems.Add(new(
new(ValidationFeedbackLevel.Warning, ValidationFeedbackRule.DuplicateEntry),
new(validator._filename, 0, 0, $"{item.Key.Key}, {item.Key.Value}")
new(validator._filename, additionalInfo: $"{item.Key.Key}, {item.Key.Value}")
));
}
}
Expand Down
4 changes: 2 additions & 2 deletions Px.Utils/Validation/DatabaseValidation/DatabaseValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ private DatabaseFileInfo GetPxFileInfo(string filename, Stream stream)
feedbacks.Add(new(
new(ValidationFeedbackLevel.Error,
ValidationFeedbackRule.NoEncoding),
new(filename, 0, 0, $"Error while reading the encoding of the file {filename}: {e.Message}"))
new(filename, additionalInfo: $"Error while reading the encoding of the file {filename}: {e.Message}"))
);
}
stream.Position = 0;
Expand Down Expand Up @@ -299,7 +299,7 @@ private async Task<DatabaseFileInfo> GetPxFileInfoAsync(string filename, Stream
feedbacks.Add(new(
new(ValidationFeedbackLevel.Error,
ValidationFeedbackRule.NoEncoding),
new(filename, 0, 0, $"Error while reading the encoding of the file {filename}: {e.Message}"))
new(filename, additionalInfo: $"Error while reading the encoding of the file {filename}: {e.Message}"))
);
}
stream.Position = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class DuplicatePxFileName(List<DatabaseFileInfo> pxFiles) : IDatabaseVali
return new(
new(ValidationFeedbackLevel.Warning,
ValidationFeedbackRule.DuplicateFileNames),
new(fileInfo.Name, 0, 0, $"Duplicate file name: {fileInfo.Name}")
new(fileInfo.Name)
);
}
else
Expand Down Expand Up @@ -55,7 +55,7 @@ public class MissingPxFileLanguages(IEnumerable<string> allLanguages) : IDatabas
return new(
new(ValidationFeedbackLevel.Warning,
ValidationFeedbackRule.FileLanguageDiffersFromDatabase),
new(fileInfo.Name, 0, 0, $"Missing languages in file {fileInfo.Name}: {string.Join(", ", _allLanguages.Except(fileInfo.Languages))}")
new(fileInfo.Name, additionalInfo: $"Missing languages: {string.Join(", ", _allLanguages.Except(fileInfo.Languages))}")
);
}
else
Expand Down Expand Up @@ -86,7 +86,7 @@ public class MismatchingEncoding(Encoding mostCommonEncoding) : IDatabaseValidat
return new (
new(ValidationFeedbackLevel.Warning,
ValidationFeedbackRule.FileEncodingDiffersFromDatabase),
new(fileInfo.Name, 0, 0, $"Inconsistent encoding in file {fileInfo.Name}: {fileInfo.Encoding.EncodingName}. " +
new(fileInfo.Name, additionalInfo: $"Inconsistent encoding: {fileInfo.Encoding.EncodingName}. " +
$"Most commonly used encoding is {_mostCommonEncoding.EncodingName}"));
}
else
Expand Down Expand Up @@ -120,7 +120,7 @@ public class MissingAliasFiles(List<DatabaseFileInfo> aliasFiles, IEnumerable<st
return new(
new(ValidationFeedbackLevel.Warning,
ValidationFeedbackRule.AliasFileMissing),
new(item.Path, 0, 0, $"Alias file for {language} in {item.Path} is missing")
new(item.Path, additionalInfo: $"Alias file for {language} is missing")
);
}
}
Expand Down
6 changes: 3 additions & 3 deletions Px.Utils/Validation/ValidationFeedback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public readonly struct ValidationFeedbackKey(ValidationFeedbackLevel level, Vali
/// <summary>
/// Stores information about a specific instance of a validation feedback rule violation.
/// </summary>
public readonly struct ValidationFeedbackValue(string filename, int line = 0, int character = 0, string? additionalInfo = null)
public readonly struct ValidationFeedbackValue(string filename, int? line = null, int? character = null, string? additionalInfo = null)
{
/// <summary>
/// Name of the file where the violation occurred.
Expand All @@ -73,11 +73,11 @@ public readonly struct ValidationFeedbackValue(string filename, int line = 0, in
/// <summary>
/// Line number where the violation occurred.
/// </summary>
public int Line { get; } = line;
public int? Line { get; } = line;
/// <summary>
/// Character position where the violation occurred.
/// </summary>
public int Character { get; } = character;
public int? Character { get; } = character;
/// <summary>
/// Additional information about the violation.
/// </summary>
Expand Down

0 comments on commit a9967c0

Please sign in to comment.