From e14916f9622592a993fad54fe184a03de0b95c7b Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 11 May 2022 17:12:58 -0400 Subject: add error code to SContentLoadException --- .../Framework/Exceptions/ContentLoadErrorType.cs | 21 +++++++++++++++++++++ .../Framework/Exceptions/SContentLoadException.cs | 15 +++++++++++++-- 2 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 src/SMAPI/Framework/Exceptions/ContentLoadErrorType.cs (limited to 'src/SMAPI/Framework/Exceptions') diff --git a/src/SMAPI/Framework/Exceptions/ContentLoadErrorType.cs b/src/SMAPI/Framework/Exceptions/ContentLoadErrorType.cs new file mode 100644 index 00000000..16689b67 --- /dev/null +++ b/src/SMAPI/Framework/Exceptions/ContentLoadErrorType.cs @@ -0,0 +1,21 @@ +namespace StardewModdingAPI.Framework.Exceptions +{ + /// Indicates why loading an asset through the content pipeline failed. + internal enum ContentLoadErrorType + { + /// The asset name is empty or has an invalid format. + InvalidName, + + /// The asset doesn't exist. + AssetDoesNotExist, + + /// The asset is not available in the current context (e.g. an attempt to load another mod's assets). + AccessDenied, + + /// The asset exists, but the data could not be deserialized or it doesn't match the expected type. + InvalidData, + + /// An unknown error occurred. + Other + } +} diff --git a/src/SMAPI/Framework/Exceptions/SContentLoadException.cs b/src/SMAPI/Framework/Exceptions/SContentLoadException.cs index be1fe748..4db24d06 100644 --- a/src/SMAPI/Framework/Exceptions/SContentLoadException.cs +++ b/src/SMAPI/Framework/Exceptions/SContentLoadException.cs @@ -6,13 +6,24 @@ namespace StardewModdingAPI.Framework.Exceptions /// An implementation of used by SMAPI to detect whether it was thrown by SMAPI or the underlying framework. internal class SContentLoadException : ContentLoadException { + /********* + ** Accessors + *********/ + /// Why loading the asset through the content pipeline failed. + public ContentLoadErrorType ErrorType { get; } + + /********* ** Public methods *********/ /// Construct an instance. + /// Why loading the asset through the content pipeline failed. /// The error message. /// The underlying exception, if any. - public SContentLoadException(string message, Exception? ex = null) - : base(message, ex) { } + public SContentLoadException(ContentLoadErrorType errorType, string message, Exception? ex = null) + : base(message, ex) + { + this.ErrorType = errorType; + } } } -- cgit