Skip to content

Commit

Permalink
Add custom exception for errors from Yaml Validator Library (#706)
Browse files Browse the repository at this point in the history
  • Loading branch information
abaskk-msft authored Jul 29, 2024
1 parent 5f489c0 commit 5b4aa54
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
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)
{
}
}

0 comments on commit 5b4aa54

Please sign in to comment.