diff --git a/src/inc/Exceptions.hpp b/src/inc/Exceptions.hpp index 99aab7c5..ff2db925 100644 --- a/src/inc/Exceptions.hpp +++ b/src/inc/Exceptions.hpp @@ -13,90 +13,10 @@ #include "Log.hpp" #include "MSIXWindows.hpp" - -#ifdef USING_XERCES - #include "xercesc/util/XMLException.hpp" - #include "xercesc/dom/DOMException.hpp" -#endif +#include "MsixErrors.hpp" namespace MSIX { - static const std::uint32_t ERROR_FACILITY = 0x8BAD0000; // Facility 2989 - static const std::uint32_t XML_FACILITY = ERROR_FACILITY + 0x1000; // XML exceptions: 0x8BAD1000 + XMLException error code - static const std::uint32_t XERCES_SAX_FACILITY = ERROR_FACILITY + 0x2000; // Xerces XMLException. 0x8BAD1000 + XMLException error code - static const std::uint32_t XERCES_XML_FACILITY = ERROR_FACILITY + 0x3000; - static const std::uint32_t XERCES_DOM_FACILITY = ERROR_FACILITY + 0x4000; - - // defines error codes - enum class Error : std::uint32_t - { - // - // Win32 error codes - // - OK = 0x00000000, - NotImplemented = 0x80004001, - NoInterface = 0x80004002, - Unexpected = 0x8000ffff, - FileNotFound = 0x80070002, - OutOfMemory = 0x8007000E, - NotSupported = 0x80070032, - InvalidParameter = 0x80070057, - Stg_E_Invalidpointer = 0x80030009, - - // - // msix specific error codes - // - - // Basic file errors - FileOpen = ERROR_FACILITY + 0x0001, - FileSeek = ERROR_FACILITY + 0x0002, - FileRead = ERROR_FACILITY + 0x0003, - FileWrite = ERROR_FACILITY + 0x0003, - FileCreateDirectory = ERROR_FACILITY + 0x0004, - FileSeekOutOfRange = ERROR_FACILITY + 0x0005, - - // Zip format errors - ZipCentralDirectoryHeader = ERROR_FACILITY + 0x0011, - ZipLocalFileHeader = ERROR_FACILITY + 0x0012, - Zip64EOCDRecord = ERROR_FACILITY + 0x0013, - Zip64EOCDLocator = ERROR_FACILITY + 0x0014, - ZipEOCDRecord = ERROR_FACILITY + 0x0015, - ZipHiddenData = ERROR_FACILITY + 0x0016, - ZipBadExtendedData = ERROR_FACILITY + 0x0017, - - // Inflate errors - InflateInitialize = ERROR_FACILITY + 0x0021, - InflateRead = ERROR_FACILITY + 0x0022, - InflateCorruptData = ERROR_FACILITY + 0x0023, - - // Package format errors - MissingAppxSignatureP7X = ERROR_FACILITY + 0x0031, - MissingContentTypesXML = ERROR_FACILITY + 0x0032, - MissingAppxBlockMapXML = ERROR_FACILITY + 0x0033, - MissingAppxManifestXML = ERROR_FACILITY + 0x0034, - DuplicateFootprintFile = ERROR_FACILITY + 0x0035, - UnknownFileNameEncoding = ERROR_FACILITY + 0x0036, - - // Signature errors - SignatureInvalid = ERROR_FACILITY + 0x0041, - CertNotTrusted = ERROR_FACILITY + 0x0042, - PublisherMismatch = ERROR_FACILITY + 0x0043, - - // Blockmap semantic errors - BlockMapSemanticError = ERROR_FACILITY + 0x0051, - - // AppxManifest semantic errors - AppxManifestSemanticError = ERROR_FACILITY + 0x0061, - - // Bundle errors - PackageIsBundle = ERROR_FACILITY + 0x0071, - - // XML parsing errors - XmlWarning = XML_FACILITY + 0x0001, - XmlError = XML_FACILITY + 0x0002, - XmlFatal = XML_FACILITY + 0x0003, - }; - // Defines a common exception type to throw in exceptional cases. DO NOT USE FOR FLOW CONTROL! // Throwing MSIX::Exception will break into the debugger on chk builds to aid debugging class Exception : public std::exception @@ -133,27 +53,6 @@ namespace MSIX { } }; -#ifdef USING_XERCES - // Provides an ABI exception boundary with parameter validation - #define CATCH_RETURN() \ - catch (const XERCES_CPP_NAMESPACE::XMLException& e) \ - { return static_cast(MSIX::XERCES_XML_FACILITY) + \ - static_cast(e.getCode()); \ - } \ - catch (const XERCES_CPP_NAMESPACE::DOMException& e) \ - { return static_cast(MSIX::XERCES_DOM_FACILITY) + \ - static_cast(e.code); \ - } \ - catch (MSIX::Exception& e) \ - { return static_cast(e.Code()); \ - } \ - catch (std::bad_alloc&) \ - { return static_cast(MSIX::Error::OutOfMemory); \ - } \ - catch (...) \ - { return static_cast(MSIX::Error::Unexpected); \ - } -#else // Provides an ABI exception boundary with parameter validation #define CATCH_RETURN() \ catch (MSIX::Exception& e) \ @@ -165,7 +64,6 @@ namespace MSIX { catch (...) \ { return static_cast(MSIX::Error::Unexpected); \ } -#endif template #ifdef WIN32 diff --git a/src/inc/MsixErrors.hpp b/src/inc/MsixErrors.hpp new file mode 100644 index 00000000..d68d4e48 --- /dev/null +++ b/src/inc/MsixErrors.hpp @@ -0,0 +1,81 @@ +// +// Copyright (C) 2017 Microsoft. All rights reserved. +// See LICENSE file in the project root for full license information. +// +#pragma once + +namespace MSIX { + + static const std::uint32_t ERROR_FACILITY = 0x8BAD0000; // Facility 2989 + static const std::uint32_t XML_FACILITY = ERROR_FACILITY + 0x1000; // XML exceptions: 0x8BAD1000 + XMLException error code + + // defines error codes + enum class Error : std::uint32_t + { + // + // Win32 error codes + // + OK = 0x00000000, + NotImplemented = 0x80004001, + NoInterface = 0x80004002, + Unexpected = 0x8000ffff, + FileNotFound = 0x80070002, + OutOfMemory = 0x8007000E, + NotSupported = 0x80070032, + InvalidParameter = 0x80070057, + Stg_E_Invalidpointer = 0x80030009, + + // + // msix specific error codes + // + + // Basic file errors + FileOpen = ERROR_FACILITY + 0x0001, + FileSeek = ERROR_FACILITY + 0x0002, + FileRead = ERROR_FACILITY + 0x0003, + FileWrite = ERROR_FACILITY + 0x0003, + FileCreateDirectory = ERROR_FACILITY + 0x0004, + FileSeekOutOfRange = ERROR_FACILITY + 0x0005, + + // Zip format errors + ZipCentralDirectoryHeader = ERROR_FACILITY + 0x0011, + ZipLocalFileHeader = ERROR_FACILITY + 0x0012, + Zip64EOCDRecord = ERROR_FACILITY + 0x0013, + Zip64EOCDLocator = ERROR_FACILITY + 0x0014, + ZipEOCDRecord = ERROR_FACILITY + 0x0015, + ZipHiddenData = ERROR_FACILITY + 0x0016, + ZipBadExtendedData = ERROR_FACILITY + 0x0017, + + // Inflate errors + InflateInitialize = ERROR_FACILITY + 0x0021, + InflateRead = ERROR_FACILITY + 0x0022, + InflateCorruptData = ERROR_FACILITY + 0x0023, + + // Package format errors + MissingAppxSignatureP7X = ERROR_FACILITY + 0x0031, + MissingContentTypesXML = ERROR_FACILITY + 0x0032, + MissingAppxBlockMapXML = ERROR_FACILITY + 0x0033, + MissingAppxManifestXML = ERROR_FACILITY + 0x0034, + DuplicateFootprintFile = ERROR_FACILITY + 0x0035, + UnknownFileNameEncoding = ERROR_FACILITY + 0x0036, + + // Signature errors + SignatureInvalid = ERROR_FACILITY + 0x0041, + CertNotTrusted = ERROR_FACILITY + 0x0042, + PublisherMismatch = ERROR_FACILITY + 0x0043, + + // Blockmap semantic errors + BlockMapSemanticError = ERROR_FACILITY + 0x0051, + + // AppxManifest semantic errors + AppxManifestSemanticError = ERROR_FACILITY + 0x0061, + + // Bundle errors + PackageIsBundle = ERROR_FACILITY + 0x0071, + + // XML parsing errors + XmlWarning = XML_FACILITY + 0x0001, + XmlError = XML_FACILITY + 0x0002, + XmlFatal = XML_FACILITY + 0x0003, + }; +} diff --git a/src/msix/CMakeLists.txt b/src/msix/CMakeLists.txt index 68eb89aa..1c8e7b7f 100644 --- a/src/msix/CMakeLists.txt +++ b/src/msix/CMakeLists.txt @@ -190,6 +190,7 @@ include(msix_resources) set(LIB_PUBLIC_HEADERS ../inc/AppxPackaging.hpp ../inc/MSIXWindows.hpp + ../inc/MsixErrors.hpp ) # Bundle specific files @@ -229,6 +230,7 @@ add_library(${PROJECT_NAME} SHARED # Copy out public headers to /src/msix configure_file(../inc/MSIXWindows.hpp ${CMAKE_CURRENT_BINARY_DIR}/MSIXWindows.hpp ) configure_file(../inc/AppxPackaging.hpp ${CMAKE_CURRENT_BINARY_DIR}/AppxPackaging.hpp) +configure_file(../inc/MsixErrors.hpp ${CMAKE_CURRENT_BINARY_DIR}/MsixErrors.hpp) # Linker and includes # Include MSIX headers