Skip to content
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
11 changes: 9 additions & 2 deletions src/Persistence/MsappPacking/MsappPackException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,20 @@ namespace Microsoft.PowerPlatform.PowerApps.Persistence.MsappPacking;
/// </summary>
public sealed class MsappPackException : Exception
{
public MsappPackException(string message)
public MsappPackException(MsappPackExceptionReason reason, string message)
: base(message)
{
Reason = reason;
}

public MsappPackException(string message, Exception innerException)
public MsappPackException(MsappPackExceptionReason reason, string message, Exception innerException)
: base(message, innerException)
{
Reason = reason;
}

/// <summary>
/// Identifies the reason why this exception was thrown.
/// </summary>
public MsappPackExceptionReason Reason { get; }
}
15 changes: 15 additions & 0 deletions src/Persistence/MsappPacking/MsappPackExceptionReason.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace Microsoft.PowerPlatform.PowerApps.Persistence.MsappPacking;

/// <summary>
/// Identifies the scenario in which an <see cref="MsappPackException"/> was thrown.
/// </summary>
public enum MsappPackExceptionReason
{
/// <summary>
/// An output file already exists and overwriting output is not enabled.
/// </summary>
OutputAlreadyExists,
}
12 changes: 6 additions & 6 deletions src/Persistence/MsappPacking/MsappPackingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,22 @@ public async Task UnpackToDirectoryAsync(
if (!options.OverwriteOutput)
{
if (File.Exists(msaprPath))
throw new MsappUnpackException($"Output file '{msaprPath}' already exists and overwriting output is not enabled.");
throw new MsappUnpackException(MsappUnpackExceptionReason.OutputAlreadyExists, $"Output file '{msaprPath}' already exists and overwriting output is not enabled.");

// Source code should all go into the same 'Src' folder, so we only need to see if it exists and has files inside
// We will silently remove any empty 'Src' folder
if (Directory.Exists(srcOutputDirectoryPath)
&& Directory.EnumerateFiles(srcOutputDirectoryPath, "*", SearchOption.AllDirectories).Any())
{
throw new MsappUnpackException($"Output folder '{srcOutputDirectoryPath}' is not empty and overwriting output is not enabled.");
throw new MsappUnpackException(MsappUnpackExceptionReason.OutputAlreadyExists, $"Output folder '{srcOutputDirectoryPath}' is not empty and overwriting output is not enabled.");
}

// Assets should all go into the same 'Assets' folder, so we only need to see if it exists and has files inside
// We will silently remove any empty 'Assets' folder
if (Directory.Exists(assetsOutputDirectoryPath)
&& Directory.EnumerateFiles(assetsOutputDirectoryPath, "*", SearchOption.AllDirectories).Any())
{
throw new MsappUnpackException($"Output folder '{assetsOutputDirectoryPath}' is not empty and overwriting output is not enabled.");
throw new MsappUnpackException(MsappUnpackExceptionReason.OutputAlreadyExists, $"Output folder '{assetsOutputDirectoryPath}' is not empty and overwriting output is not enabled.");
}
}

Expand Down Expand Up @@ -132,10 +132,10 @@ public async Task UnpackToDirectoryAsync(
internal static void ValidateMsappUnpackIsSupported(MsappArchive msappArchive)
{
if (msappArchive.MSAppStructureVersion < MinSupportedMSAppStructureVersion)
throw new MsappUnpackException($"MSAppStructureVersion {msappArchive.MSAppStructureVersion} is below the minimum supported version {MinSupportedMSAppStructureVersion}.");
throw new MsappUnpackException(MsappUnpackExceptionReason.UnsupportedMSAppStructureVersion, $"MSAppStructureVersion {msappArchive.MSAppStructureVersion} is below the minimum supported version {MinSupportedMSAppStructureVersion}.");

if (msappArchive.DocVersion < MinSupportedDocVersion)
throw new MsappUnpackException($"DocVersion {msappArchive.DocVersion} is below the minimum supported version {MinSupportedDocVersion}.");
throw new MsappUnpackException(MsappUnpackExceptionReason.UnsupportedDocVersion, $"DocVersion {msappArchive.DocVersion} is below the minimum supported version {MinSupportedDocVersion}.");
}

private static MsaprHeaderJson CreateMsaprHeaderJson(UnpackedConfiguration unpackedConfig)
Expand Down Expand Up @@ -235,7 +235,7 @@ public async Task PackFromMsappReferenceFileAsync(
msaprPath = Path.GetFullPath(msaprPath);

if (!options.OverwriteOutput && File.Exists(outputMsappPath))
throw new MsappPackException($"Output file '{outputMsappPath}' already exists and overwriting output is not enabled.");
throw new MsappPackException(MsappPackExceptionReason.OutputAlreadyExists, $"Output file '{outputMsappPath}' already exists and overwriting output is not enabled.");

var unpackedFolderPath = Path.GetDirectoryName(msaprPath)!;

Expand Down
11 changes: 9 additions & 2 deletions src/Persistence/MsappPacking/MsappUnpackException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,20 @@ namespace Microsoft.PowerPlatform.PowerApps.Persistence.MsappPacking;
/// </summary>
public sealed class MsappUnpackException : Exception
{
public MsappUnpackException(string message)
public MsappUnpackException(MsappUnpackExceptionReason reason, string message)
: base(message)
{
Reason = reason;
}

public MsappUnpackException(string message, Exception innerException)
public MsappUnpackException(MsappUnpackExceptionReason reason, string message, Exception innerException)
: base(message, innerException)
{
Reason = reason;
}

/// <summary>
/// Identifies the reason why this exception was thrown.
/// </summary>
public MsappUnpackExceptionReason Reason { get; }
}
25 changes: 25 additions & 0 deletions src/Persistence/MsappPacking/MsappUnpackExceptionReason.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace Microsoft.PowerPlatform.PowerApps.Persistence.MsappPacking;

/// <summary>
/// Identifies the scenario in which an <see cref="MsappUnpackException"/> was thrown.
/// </summary>
public enum MsappUnpackExceptionReason
{
/// <summary>
/// An output file or folder already exists and overwriting output is not enabled.
/// </summary>
OutputAlreadyExists,

/// <summary>
/// The MSApp structure version is below the minimum supported version.
/// </summary>
UnsupportedMSAppStructureVersion,

/// <summary>
/// The document version is below the minimum supported version.
/// </summary>
UnsupportedDocVersion,
}
Loading