Merged PR 2467663: Move MSIX::Error to its own header

Having the errors being in its own header allows developers to include MsixError.hpp in their project and don't have to redefine any MSIX SDK specific errors.

Also, removing some unnecessary xerces dead code.

Related work items: #19262316
This commit is contained in:
Ruben Guerrero Samaniego 2018-10-17 19:19:14 +00:00 коммит произвёл Adrian Mascarenhas
Родитель dd959738f0
Коммит 5913c2712c
3 изменённых файлов: 84 добавлений и 103 удалений

Просмотреть файл

@ -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<HRESULT>(MSIX::XERCES_XML_FACILITY) + \
static_cast<HRESULT>(e.getCode()); \
} \
catch (const XERCES_CPP_NAMESPACE::DOMException& e) \
{ return static_cast<HRESULT>(MSIX::XERCES_DOM_FACILITY) + \
static_cast<HRESULT>(e.code); \
} \
catch (MSIX::Exception& e) \
{ return static_cast<HRESULT>(e.Code()); \
} \
catch (std::bad_alloc&) \
{ return static_cast<HRESULT>(MSIX::Error::OutOfMemory); \
} \
catch (...) \
{ return static_cast<HRESULT>(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<HRESULT>(MSIX::Error::Unexpected); \
}
#endif
template <typename E, class C>
#ifdef WIN32

81
src/inc/MsixErrors.hpp Normal file
Просмотреть файл

@ -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,
};
}

Просмотреть файл

@ -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 <binary dir>/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