Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom exception for errors from Yaml Validator Library #706

Merged
merged 3 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/YamlValidator/SchemaLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public JsonSchema Load()
var assemblyName = assembly.GetName().Name;
if (fileStream == null)
{
throw new IOException($"Resource {file} could not found in assembly {assemblyName}");
throw new YamlValidatorLibraryException($"The schema could not be loaded from assembly.");
}
using var streamReader = new StreamReader(fileStream);
var jsonSchemaString = streamReader.ReadToEnd();
Expand All @@ -45,7 +45,7 @@ public JsonSchema Load()
}
if (node == null)
{
throw new InvalidDataException("Schema was not able to be read into memory");
throw new YamlValidatorLibraryException("The schema could not be serialized from the assembly.");
}
return node;
}
Expand Down
4 changes: 2 additions & 2 deletions src/YamlValidator/ValidatorError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public override string ToString()
foreach (var error in Errors)
{
var errType = string.IsNullOrEmpty(error.Key) ? "Error" : error.Key;
errString += $"\t{errType}: {error.Value}\n";
errString += $"\t\t- {errType}: {error.Value}\n";
}
}
return $"InstanceLocation: {InstanceLocation}\nSchemaPath: {SchemaPath}\nErrors:\n{errString}";
return $"\t- InstanceLocation: {InstanceLocation}\n\t- SchemaPath: {SchemaPath}\n\t- Errors:\n{errString}";
}
}
10 changes: 10 additions & 0 deletions src/YamlValidator/YamlValidatorLibraryException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace Microsoft.PowerPlatform.PowerApps.Persistence.YamlValidator;
public class YamlValidatorLibraryException : Exception
{
public YamlValidatorLibraryException(string reason) : base(message: reason)
{
}
}
Loading