Microsoft Information Protection (MIP) SDK for C++: Reference 1.16
Doxygen-generated documentation for MIP SDK written in C++
Loading...
Searching...
No Matches
BadInputError Class Referenceabstract

Bad input error, thrown when the input to an SDK API is invalid. More...

#include <src/api/mip/error.h>

Inheritance diagram for BadInputError:
Collaboration diagram for BadInputError:

Public Types

enum class  ErrorCode {
  General = 0 , FileIsTooLargeForProtection = 1 , ParameterParsing = 2 , LicenseNotTrusted = 3 ,
  DoubleKey = 4 , FileFormatNotSupported = 5
}
 ErrorCode of bad input error. More...
 

Public Member Functions

void AddDebugInfo (const std::string &key, const std::string &value, bool sensitive=false)
 Add debug info entry.
 
virtual std::shared_ptr< ErrorClone () const =0
 Clone the error.
 
const std::map< std::string, std::string > & GetDebugInfo () const
 Get debug info.
 
ErrorCode GetErrorCode () const
 Gets the errorCode of bad input.
 
const std::string & GetErrorName () const
 Get the error name.
 
virtual ErrorType GetErrorType () const
 Get the error type.
 
const std::string & GetMessage (bool maskPII=false) const
 Get the error message.
 
void SetMessage (const std::string &msg)
 Set the error message.
 
char const * what () const noexcept override
 Get the error message.
 

Public Attributes

std::map< std::string, std::string > mDebugInfo
 
std::string mMessage
 
std::string mName
 
ErrorType mType
 

Private Member Functions

std::string CreateFormattedMessage (const std::string &message) const
 
const std::string & GetErrorCodeString (ErrorCode code) const
 

Private Attributes

ErrorCode mErrorCode
 
std::string mFormattedMessage
 
std::string mMaskedMessage
 

Detailed Description

Bad input error, thrown when the input to an SDK API is invalid.

Definition at line 247 of file error.h.

Member Enumeration Documentation

◆ ErrorCode

enum class BadInputError::ErrorCode
strong

ErrorCode of bad input error.

Enumerator
General 

General bad input error

FileIsTooLargeForProtection 

File is too large for protection

ParameterParsing 

Parameter cannot be parsed correctly

LicenseNotTrusted 

Publishing license not issued by trusted source

DoubleKey 

A paremeter for double key encryption is needed and missing

FileFormatNotSupported 

The input file's format is not supported

Definition at line 253 of file error.h.

253 {
254 General = 0, /**< General bad input error */
255 FileIsTooLargeForProtection = 1, /**< File is too large for protection */
256 ParameterParsing = 2, /**< Parameter cannot be parsed correctly */
257 LicenseNotTrusted = 3, /**< Publishing license not issued by trusted source */
258 DoubleKey = 4, /**< A paremeter for double key encryption is needed and missing */
259 FileFormatNotSupported = 5, /**<The input file's format is not supported */
260 };

Member Function Documentation

◆ AddDebugInfo()

void Error::AddDebugInfo ( const std::string & key,
const std::string & value,
bool sensitive = false )
inlineinherited

Add debug info entry.

Parameters
keyDebug info key
valueDebug info value

Definition at line 179 of file error.h.

179 {
180 if (!key.empty() && !value.empty()) {
181 mDebugInfo[key] = value;
182 mFormattedMessage = mFormattedMessage + ", " + key + "=" + value;
183 mMaskedMessage = mMaskedMessage + ", " + key + "=" + (sensitive ? "***" : value);
184 }
185 }
std::map< std::string, std::string > mDebugInfo
Definition error.h:225
std::string mMaskedMessage
Definition error.h:241
std::string mFormattedMessage
Definition error.h:240

References Error::mDebugInfo, Error::mFormattedMessage, and Error::mMaskedMessage.

Referenced by NoPermissionsExtendedError::AddExtendedErrorInfoToDebugInfo(), DelegateResponseError::DelegateResponseError(), DelegateResponseError::DelegateResponseError(), and DelegateResponseError::DelegateResponseError().

◆ Clone()

virtual std::shared_ptr< Error > Error::Clone ( ) const
pure virtualinherited

Clone the error.

Returns
a clone of the error.

Implemented in JustificationRequiredError.

◆ CreateFormattedMessage()

std::string Error::CreateFormattedMessage ( const std::string & message) const
inlineprivateinherited

Definition at line 230 of file error.h.

230 {
231 auto formattedMessage = message;
232
233 // Remove stray newlines
234 auto isNewlineFn = [](char c) { return c == '\n' || c == '\r'; };
235 formattedMessage.erase(std::remove_if(formattedMessage.begin(), formattedMessage.end(), isNewlineFn), formattedMessage.end());
236
237 return formattedMessage;
238 }

◆ GetDebugInfo()

const std::map< std::string, std::string > & Error::GetDebugInfo ( ) const
inlineinherited

Get debug info.

Returns
Debug info (keys/values)

Definition at line 192 of file error.h.

192{ return mDebugInfo; }

References Error::mDebugInfo.

◆ GetErrorCode()

ErrorCode BadInputError::GetErrorCode ( ) const
inline

Gets the errorCode of bad input.

Returns
ErrorCode of bad input error

Definition at line 293 of file error.h.

293{ return mErrorCode; }
ErrorCode mErrorCode
Definition error.h:296

References mErrorCode.

◆ GetErrorCodeString()

const std::string & BadInputError::GetErrorCodeString ( ErrorCode code) const
inlineprivate

Definition at line 298 of file error.h.

298 {
299 static const std::string kUnrecognized = "UNRECOGNIZED";
300 static const std::map<ErrorCode, std::string> kCodes = {
301 { ErrorCode::General, "General" },
302 { ErrorCode::FileIsTooLargeForProtection, "FileIsTooLargeForProtection" },
303 { ErrorCode::ParameterParsing, "ParameterParsing" },
304 { ErrorCode::LicenseNotTrusted, "LicenseNotTrusted" },
305 { ErrorCode::DoubleKey, "DoubleKey" },
306 { ErrorCode::FileFormatNotSupported, "FileFormatNotSupported"},
307 };
308 return kCodes.count(code) ? kCodes.at(code) : kUnrecognized;
309 }

References DoubleKey, FileFormatNotSupported, FileIsTooLargeForProtection, General, LicenseNotTrusted, and ParameterParsing.

◆ GetErrorName()

const std::string & Error::GetErrorName ( ) const
inlineinherited

Get the error name.

Returns
the error name.

Definition at line 144 of file error.h.

144{ return mName; }
std::string mName
Definition error.h:226

References Error::mName.

◆ GetErrorType()

virtual ErrorType Error::GetErrorType ( ) const
inlinevirtualinherited

Get the error type.

Returns
the error type.

Definition at line 137 of file error.h.

137{ return mType; }
ErrorType mType
Definition error.h:227

References Error::mType.

◆ GetMessage()

const std::string & Error::GetMessage ( bool maskPII = false) const
inlineinherited

Get the error message.

Returns
the error message.

Definition at line 151 of file error.h.

151 {
152 return maskPII ? mMaskedMessage : mFormattedMessage;
153 }

References Error::mFormattedMessage, and Error::mMaskedMessage.

◆ SetMessage()

void Error::SetMessage ( const std::string & msg)
inlineinherited

Set the error message.

Parameters
msgthe error message.

Definition at line 160 of file error.h.

160 {
161 std::string* targetStrings[] = { &mFormattedMessage, &mMaskedMessage };
162 for (auto* targetString : targetStrings) {
163 size_t pos = targetString->find(mMessage);
164 if (pos != std::string::npos) {
165 targetString->replace(pos, mMessage.length(), msg);
166 } else {
167 targetString->replace(0, 0, msg);
168 }
169 }
170 mMessage = msg;
171 }
std::string mMessage
Definition error.h:224

References Error::mFormattedMessage, Error::mMaskedMessage, and Error::mMessage.

◆ what()

char const * Error::what ( ) const
inlineoverridenoexceptinherited

Get the error message.

Returns
the error message

Definition at line 121 of file error.h.

121 {
122 return mFormattedMessage.c_str();
123 }

References Error::mFormattedMessage.

Member Data Documentation

◆ mDebugInfo

std::map<std::string, std::string> Error::mDebugInfo
inherited

Definition at line 225 of file error.h.

Referenced by Error::AddDebugInfo(), and Error::GetDebugInfo().

◆ mErrorCode

ErrorCode BadInputError::mErrorCode
private

Definition at line 296 of file error.h.

Referenced by GetErrorCode().

◆ mFormattedMessage

std::string Error::mFormattedMessage
privateinherited

Definition at line 240 of file error.h.

Referenced by Error::AddDebugInfo(), Error::GetMessage(), Error::SetMessage(), and Error::what().

◆ mMaskedMessage

std::string Error::mMaskedMessage
privateinherited

Definition at line 241 of file error.h.

Referenced by Error::AddDebugInfo(), Error::GetMessage(), and Error::SetMessage().

◆ mMessage

std::string Error::mMessage
inherited

Definition at line 224 of file error.h.

Referenced by DelegateResponseError::DelegateResponseError(), and Error::SetMessage().

◆ mName

std::string Error::mName
inherited

Definition at line 226 of file error.h.

Referenced by Error::GetErrorName().

◆ mType

ErrorType Error::mType
inherited

Definition at line 227 of file error.h.

Referenced by Error::GetErrorType().


The documentation for this class was generated from the following file: