Skip to content

Commit

Permalink
Rename PersistenceException to PaPersistenceException so it's una…
Browse files Browse the repository at this point in the history
…mbiguous with similar type in DocSvr
  • Loading branch information
joem-msft committed May 8, 2024
1 parent 3cd99b7 commit d55c489
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static ExceptionAssertions<TException> WithErrorCode<TException>(
PersistenceErrorCode errorCode,
string? because = null,
params object[] becauseArgs)
where TException : PersistenceException
where TException : PaPersistenceException
{
_ = assertion ?? throw new ArgumentNullException(nameof(assertion));

Expand All @@ -36,7 +36,7 @@ public static ExceptionAssertions<TException> WithReason<TException>(
string? wildcardPattern,
string? because = null,
params object[] becauseArgs)
where TException : PersistenceException
where TException : PaPersistenceException
{
_ = assertion ?? throw new ArgumentNullException(nameof(assertion));

Expand Down
2 changes: 1 addition & 1 deletion src/Persistence.Tests/MsApp/MsappArchiveTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void AddEntryTests(string[] entries, string[] expectedEntries)
}

// Get the required entry should throw if it doesn't exist
msappArchive.Invoking(a => a.GetRequiredEntry("not-exist")).Should().Throw<PersistenceException>()
msappArchive.Invoking(a => a.GetRequiredEntry("not-exist")).Should().Throw<PaPersistenceException>()
.WithErrorCode(PersistenceErrorCode.MsappArchiveError);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Persistence.Tests/MsApp/RoundTripWriterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void Write_Should_Fail(string input, string output, int line, int column)
};

// Assert
var thrownEx = act.Should().ThrowExactly<PersistenceException>()
var thrownEx = act.Should().ThrowExactly<PaPersistenceException>()
.WithErrorCode(PersistenceErrorCode.RoundTripValidationFailed)
.Which;
thrownEx.MsappEntryFullPath.Should().Be("test");
Expand Down
20 changes: 10 additions & 10 deletions src/Persistence.Tests/PersistenceExceptionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ public class PersistenceExceptionTests
[TestMethod]
public void ConstructTest()
{
ThrowAndVerify(new PersistenceException(PersistenceErrorCode.DeserializationError))
ThrowAndVerify(new PaPersistenceException(PersistenceErrorCode.DeserializationError))
.WithErrorCode(PersistenceErrorCode.DeserializationError)
.WithReason(null);
ThrowAndVerify(new PersistenceException(PersistenceErrorCode.SerializationError, "A test reason."))
ThrowAndVerify(new PaPersistenceException(PersistenceErrorCode.SerializationError, "A test reason."))
.WithErrorCode(PersistenceErrorCode.SerializationError)
.WithReason("A test reason.");
ThrowAndVerify(new PersistenceException(PersistenceErrorCode.MsappArchiveError, "A test reason2.")
ThrowAndVerify(new PaPersistenceException(PersistenceErrorCode.MsappArchiveError, "A test reason2.")
{
MsappEntryFullPath = "src/entry1.txt",
LineNumber = 5,
Expand All @@ -32,17 +32,17 @@ public void ConstructTest()
[TestMethod]
public void MessageTest()
{
ThrowAndVerify(new PersistenceException(PersistenceErrorCode.DeserializationError))
ThrowAndVerify(new PaPersistenceException(PersistenceErrorCode.DeserializationError))
.WithMessage("[3000:DeserializationError] An error occurred during deserialization.");
ThrowAndVerify(new PersistenceException(PersistenceErrorCode.SerializationError, "A test reason."))
ThrowAndVerify(new PaPersistenceException(PersistenceErrorCode.SerializationError, "A test reason."))
.WithMessage("[2000:SerializationError] An error occurred during serialization. A test reason.");
ThrowAndVerify(new PersistenceException(PersistenceErrorCode.YamlInvalidSyntax)
ThrowAndVerify(new PaPersistenceException(PersistenceErrorCode.YamlInvalidSyntax)
{
LineNumber = 5,
Column = 3,
})
.WithMessage("[3001:YamlInvalidSyntax] Invalid YAML syntax was encountered during deserialization. Line: 5; Column: 3;");
ThrowAndVerify(new PersistenceException(PersistenceErrorCode.MsappArchiveError, "A test reason2.")
ThrowAndVerify(new PaPersistenceException(PersistenceErrorCode.MsappArchiveError, "A test reason2.")
{
MsappEntryFullPath = "src/entry1.txt",
LineNumber = 5,
Expand All @@ -55,9 +55,9 @@ public void MessageTest()
[TestMethod]
public void IsSerializableTests()
{
new PersistenceException(PersistenceErrorCode.DeserializationError).Should().BeBinarySerializable();
new PersistenceException(PersistenceErrorCode.SerializationError, "A test reason.").Should().BeBinarySerializable();
new PersistenceException(PersistenceErrorCode.MsappArchiveError, "A test reason2.")
new PaPersistenceException(PersistenceErrorCode.DeserializationError).Should().BeBinarySerializable();
new PaPersistenceException(PersistenceErrorCode.SerializationError, "A test reason.").Should().BeBinarySerializable();
new PaPersistenceException(PersistenceErrorCode.MsappArchiveError, "A test reason2.")
{
MsappEntryFullPath = "src/entry1.txt",
LineNumber = 5,
Expand Down
6 changes: 3 additions & 3 deletions src/Persistence.Tests/Yaml/DeserializerInvalidTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void Deserialize_ShouldFailWhenYamlIsInvalid(bool isControlIdentifiers)
var yaml = File.ReadAllText(filePath);
using var yamlReader = new StringReader(yaml);
var act = () => deserializer.Deserialize<Control>(yamlReader);
act.Should().ThrowExactly<PersistenceException>("deserializing file '{0}' is expected to be invalid", filePath)
act.Should().ThrowExactly<PaPersistenceException>("deserializing file '{0}' is expected to be invalid", filePath)
.WithErrorCode(PersistenceErrorCode.DeserializationError)
.WithInnerExceptionExactly<YamlException>();
}
Expand All @@ -48,7 +48,7 @@ public void Deserialize_ShouldFailWhenExpectingDifferentType(bool isControlIdent
Action act = () => { deserializer.Deserialize<BuiltInControl>(yamlReader); };

// Assert
act.Should().Throw<PersistenceException>()
act.Should().Throw<PaPersistenceException>()
.WithErrorCode(PersistenceErrorCode.DeserializationError)
.WithInnerExceptionExactly<YamlException>()
.WithInnerException<NotSupportedException>()
Expand Down Expand Up @@ -78,7 +78,7 @@ public void Deserialize_Screens_List(string path, bool isControlIdentifiers)
};

// Assert
act.Should().Throw<PersistenceException>()
act.Should().Throw<PaPersistenceException>()
.WithErrorCode(PersistenceErrorCode.DeserializationError)
.WithReason("Duplicate control property*")
.WithInnerExceptionExactly<YamlException>();
Expand Down
14 changes: 7 additions & 7 deletions src/Persistence/MsApp/MsappArchive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public DataSources? DataSources
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
/// <exception cref="InvalidOperationException"></exception>
/// <exception cref="PersistenceException"></exception>
/// <exception cref="PaPersistenceException"></exception>
public T Deserialize<T>(string entryName, bool ensureRoundTrip = true) where T : Control
{
if (string.IsNullOrWhiteSpace(entryName))
Expand Down Expand Up @@ -292,11 +292,11 @@ public T Deserialize<T>(ZipArchiveEntry archiveEntry) where T : Control
_ = archiveEntry ?? throw new ArgumentNullException(nameof(archiveEntry));

if (!archiveEntry.FullName.EndsWith(YamlFileExtension, StringComparison.OrdinalIgnoreCase))
throw new PersistenceException(PersistenceErrorCode.MsappArchiveError, $"Entry {archiveEntry} is not a yaml file.") { MsappEntryFullPath = archiveEntry.FullName };
throw new PaPersistenceException(PersistenceErrorCode.MsappArchiveError, $"Entry {archiveEntry} is not a yaml file.") { MsappEntryFullPath = archiveEntry.FullName };

using var textReader = new StreamReader(archiveEntry.Open());
return _yamlDeserializer.Deserialize<T>(textReader)
?? throw new PersistenceException(PersistenceErrorCode.EditorStateJsonEmptyOrNull, "Deserialization of file resulted in null object.") { MsappEntryFullPath = archiveEntry.FullName };
?? throw new PaPersistenceException(PersistenceErrorCode.EditorStateJsonEmptyOrNull, "Deserialization of file resulted in null object.") { MsappEntryFullPath = archiveEntry.FullName };
}

/// <summary>
Expand Down Expand Up @@ -346,11 +346,11 @@ public IEnumerable<ZipArchiveEntry> GetDirectoryEntries(string directoryName, st
/// <param name="entryName"></param>
/// <returns></returns>
/// <exception cref="ArgumentException"></exception>
/// <exception cref="PersistenceException"></exception>
/// <exception cref="PaPersistenceException"></exception>
public ZipArchiveEntry GetRequiredEntry(string entryName)
{
return GetEntry(entryName) ??
throw new PersistenceException(PersistenceErrorCode.MsappArchiveError, $"Entry with name '{entryName}' not found in msapp archive.");
throw new PaPersistenceException(PersistenceErrorCode.MsappArchiveError, $"Entry with name '{entryName}' not found in msapp archive.");
}

/// <inheritdoc/>
Expand Down Expand Up @@ -632,11 +632,11 @@ private static T DeserializeMsappJsonFile<T>(ZipArchiveEntry entry)
try
{
return JsonSerializer.Deserialize<T>(entry.Open())
?? throw new PersistenceException(PersistenceErrorCode.EditorStateJsonEmptyOrNull, "Deserialization of json file resulted in null object.") { MsappEntryFullPath = entry.FullName };
?? throw new PaPersistenceException(PersistenceErrorCode.EditorStateJsonEmptyOrNull, "Deserialization of json file resulted in null object.") { MsappEntryFullPath = entry.FullName };
}
catch (JsonException ex)
{
throw new PersistenceException(PersistenceErrorCode.InvalidEditorStateJson, $"Failed to deserialize json file to an instance of {typeof(T).Name}.", ex)
throw new PaPersistenceException(PersistenceErrorCode.InvalidEditorStateJson, $"Failed to deserialize json file to an instance of {typeof(T).Name}.", ex)
{
MsappEntryFullPath = entry.FullName,
LineNumber = ex.LineNumber,
Expand Down
4 changes: 2 additions & 2 deletions src/Persistence/MsApp/RoundTripWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public override void Write(char value)
if (inputValue == -1 || inputValue != value)
{
_exThrown = true;
throw new PersistenceException(PersistenceErrorCode.RoundTripValidationFailed, $"Round trip serialization failed")
throw new PaPersistenceException(PersistenceErrorCode.RoundTripValidationFailed, $"Round trip serialization failed")
{
MsappEntryFullPath = _entryFullPath,
LineNumber = _lineNumber,
Expand All @@ -72,7 +72,7 @@ protected override void Dispose(bool disposing)
var inputValue = _input.Read();
if (inputValue != -1)
{
throw new PersistenceException(PersistenceErrorCode.RoundTripValidationFailed, $"Round trip serialization failed. Additional input not read when disposing.")
throw new PaPersistenceException(PersistenceErrorCode.RoundTripValidationFailed, $"Round trip serialization failed. Additional input not read when disposing.")
{
MsappEntryFullPath = _entryFullPath,
LineNumber = _lineNumber,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,30 @@
namespace Microsoft.PowerPlatform.PowerApps.Persistence;

[Serializable]
public class PersistenceException : Exception
public class PaPersistenceException : Exception
{
public PersistenceException(PersistenceErrorCode errorCode)
public PaPersistenceException(PersistenceErrorCode errorCode)
: this(errorCode, null, null)
{
}

public PersistenceException(PersistenceErrorCode errorCode, string reason)
public PaPersistenceException(PersistenceErrorCode errorCode, string reason)
: this(errorCode, reason, null)
{
}

public PersistenceException(PersistenceErrorCode errorCode, Exception innerException)
public PaPersistenceException(PersistenceErrorCode errorCode, Exception innerException)
: this(errorCode, null, innerException)
{
}

public PersistenceException(PersistenceErrorCode errorCode, string? reason, Exception? innerException)
public PaPersistenceException(PersistenceErrorCode errorCode, string? reason, Exception? innerException)
: base(reason ?? string.Empty, innerException) // Convert reason to non-null so base.Message doesn't get set to the default ex message.
{
ErrorCode = errorCode.CheckArgumentInRange();
}

protected PersistenceException(SerializationInfo info, StreamingContext context)
protected PaPersistenceException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
ErrorCode = ((PersistenceErrorCode)info.GetInt32(nameof(ErrorCode))).CheckArgumentInRange();
Expand Down Expand Up @@ -114,11 +114,11 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont
base.GetObjectData(info, context);
}

internal static PersistenceException FromYamlException(YamlException ex, PersistenceErrorCode errorCode)
internal static PaPersistenceException FromYamlException(YamlException ex, PersistenceErrorCode errorCode)
{
return ex.Start.Equals(Mark.Empty)
? new PersistenceException(errorCode, ex.Message, ex)
: new PersistenceException(errorCode, ex.Message, ex)
? new PaPersistenceException(errorCode, ex.Message, ex)
: new PaPersistenceException(errorCode, ex.Message, ex)
{
LineNumber = ex.Start.Line,
Column = ex.Start.Column,
Expand Down
4 changes: 2 additions & 2 deletions src/Persistence/PaYaml/Serialization/PaYamlSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private static void WriteTextWriter<TValue>(TextWriter writer, in TValue? value,
}
catch (YamlException ex)
{
throw PersistenceException.FromYamlException(ex, PersistenceErrorCode.SerializationError);
throw PaPersistenceException.FromYamlException(ex, PersistenceErrorCode.SerializationError);
}
}
#endregion
Expand Down Expand Up @@ -117,7 +117,7 @@ private static void WriteTextWriter<TValue>(TextWriter writer, in TValue? value,
}
catch (YamlException ex)
{
throw PersistenceException.FromYamlException(ex, PersistenceErrorCode.YamlInvalidSyntax);
throw PaPersistenceException.FromYamlException(ex, PersistenceErrorCode.YamlInvalidSyntax);
}

// TODO: Consider using FluentValidation nuget package to validate the deserialized object
Expand Down
4 changes: 2 additions & 2 deletions src/Persistence/Yaml/IYamlDeserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ namespace Microsoft.PowerPlatform.PowerApps.Persistence.Yaml;

public interface IYamlDeserializer
{
/// <exception cref="PersistenceException">Thrown when an error occurs while deserializing.</exception>
/// <exception cref="PaPersistenceException">Thrown when an error occurs while deserializing.</exception>
public T? Deserialize<T>(string yaml) where T : notnull;

/// <exception cref="PersistenceException">Thrown when an error occurs while deserializing.</exception>
/// <exception cref="PaPersistenceException">Thrown when an error occurs while deserializing.</exception>
public T? Deserialize<T>(TextReader reader) where T : notnull;
}
6 changes: 3 additions & 3 deletions src/Persistence/Yaml/IYamlSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ namespace Microsoft.PowerPlatform.PowerApps.Persistence.Yaml;

public interface IYamlSerializer
{
/// <exception cref="PersistenceException">Thrown when an error occurs while serializing.</exception>
/// <exception cref="PaPersistenceException">Thrown when an error occurs while serializing.</exception>
public string Serialize(object graph);

/// <exception cref="PersistenceException">Thrown when an error occurs while serializing.</exception>
/// <exception cref="PaPersistenceException">Thrown when an error occurs while serializing.</exception>
public string SerializeControl<T>(T graph) where T : Control;

/// <exception cref="PersistenceException">Thrown when an error occurs while serializing.</exception>
/// <exception cref="PaPersistenceException">Thrown when an error occurs while serializing.</exception>
public void SerializeControl<T>(TextWriter writer, T graph) where T : Control;
}
2 changes: 1 addition & 1 deletion src/Persistence/Yaml/YamlDeserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ internal YamlDeserializer(IDeserializer deserializer)
}
catch (YamlException ex)
{
throw PersistenceException.FromYamlException(ex, PersistenceErrorCode.DeserializationError);
throw PaPersistenceException.FromYamlException(ex, PersistenceErrorCode.DeserializationError);
}
}
}
4 changes: 2 additions & 2 deletions src/Persistence/Yaml/YamlSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private void SerializeCore<T>(TextWriter writer, T graph)
}
catch (YamlException ex)
{
throw PersistenceException.FromYamlException(ex, PersistenceErrorCode.SerializationError);
throw PaPersistenceException.FromYamlException(ex, PersistenceErrorCode.SerializationError);
}
}

Expand All @@ -58,7 +58,7 @@ private string SerializeCore<T>(T graph)
}
catch (YamlException ex)
{
throw PersistenceException.FromYamlException(ex, PersistenceErrorCode.SerializationError);
throw PaPersistenceException.FromYamlException(ex, PersistenceErrorCode.SerializationError);
}
}
}

0 comments on commit d55c489

Please sign in to comment.