Merge branch 'feature/enhanced_error_logging' into 'release/10_5_1'
Omar's enhanced error logging initiative. ### Summary Omar's enhanced error logging initiative. See merge request https://gitlab.verizon.com/BPHV_MIPS/mvm_core_ui/-/merge_requests/934
This commit is contained in:
commit
aca8b8f44a
@ -132,9 +132,9 @@ import MVMCore
|
||||
try parsePageJSON()
|
||||
} catch let parsingError {
|
||||
// Log all parsing errors and fail load.
|
||||
handleLoggingFor(parsingError: parsingError)
|
||||
if let errorObject = MVMCoreErrorObject.createErrorObject(for: parsingError, location: MVMCoreLoadHandler.sharedGlobal()?.errorLocation(forRequest: loadObject)) {
|
||||
if let errorObject = MVMCoreLoadHandler.sharedGlobal()?.error(for: loadObject, causedBy: parsingError) {
|
||||
errorObject.messageToDisplay = MVMCoreGetterUtility.hardcodedString(withKey: HardcodedErrorUnableToProcess)
|
||||
errorObject.messageToLog = describe(parsingError: parsingError)
|
||||
error.pointee = errorObject
|
||||
}
|
||||
return false
|
||||
@ -149,37 +149,38 @@ import MVMCore
|
||||
return true
|
||||
}
|
||||
|
||||
func handleLoggingFor(parsingError: Error) {
|
||||
func describe(parsingError: Error) -> String {
|
||||
if let registryError = parsingError as? ModelRegistry.Error {
|
||||
switch (registryError) {
|
||||
case .decoderErrorModelNotMapped(let identifier, let codingKey, let codingPath) where identifier != nil && codingKey != nil && codingPath != nil:
|
||||
MVMCoreLoggingHandler.shared()?.handleDebugMessage("Error parsing template: Model identifier \"\(identifier!)\" is not mapped for \"\(codingKey!.stringValue)\" @ \(codingPath!.map { return $0.stringValue })")
|
||||
return "Error parsing template. Model identifier \"\(identifier!)\" is not mapped for \"\(codingKey!.stringValue)\" @ \(codingPath!.map { return $0.stringValue })"
|
||||
|
||||
case .decoderErrorObjectNotPresent(let codingKey, codingPath: let codingPath):
|
||||
MVMCoreLoggingHandler.shared()?.handleDebugMessage("Error parsing template: Required model \"\(codingKey.stringValue)\" was not found @ \(codingPath.map { return $0.stringValue })")
|
||||
case .decoderErrorObjectNotPresent(let codingKey, let codingPath):
|
||||
return "Error parsing template. Required model \"\(codingKey.stringValue)\" was not found @ \(codingPath.map { return $0.stringValue })"
|
||||
|
||||
default:
|
||||
MVMCoreLoggingHandler.shared()?.handleDebugMessage("Error parsing template: Registry error: \(registryError)")
|
||||
return "Error parsing template. Registry error: \((registryError as NSError).localizedFailureReason ?? registryError.localizedDescription)"
|
||||
}
|
||||
}
|
||||
if let decodingError = parsingError as? DecodingError {
|
||||
switch (decodingError) {
|
||||
case .keyNotFound(let codingKey, let context):
|
||||
MVMCoreLoggingHandler.shared()?.handleDebugMessage("Error parsing template: Key \(codingKey.stringValue) was not found @ \(context.codingPath.map { return $0.stringValue })")
|
||||
return "Error parsing template. Required key \(codingKey.stringValue) was not found @ \(context.codingPath.map { return $0.stringValue })"
|
||||
|
||||
case .valueNotFound(_, let context):
|
||||
MVMCoreLoggingHandler.shared()?.handleDebugMessage("Error parsing template: Value not found @ \(context.codingPath.map { return $0.stringValue })")
|
||||
return "Error parsing template. Value not found @ \(context.codingPath.map { return $0.stringValue })"
|
||||
|
||||
case .typeMismatch(_, let context):
|
||||
MVMCoreLoggingHandler.shared()?.handleDebugMessage("Error parsing template: Type mismatch @ \(context.codingPath.map { return $0.stringValue })")
|
||||
return "Error parsing template. Value type mismatch @ \(context.codingPath.map { return $0.stringValue })"
|
||||
|
||||
case .dataCorrupted(let context):
|
||||
MVMCoreLoggingHandler.shared()?.handleDebugMessage("Error parsing template: Data corrupted @ \(context.codingPath.map { return $0.stringValue })")
|
||||
return "Error parsing template. Data corrupted @ \(context.codingPath.map { return $0.stringValue })"
|
||||
|
||||
@unknown default:
|
||||
MVMCoreLoggingHandler.shared()?.handleDebugMessage("Error parsing template: \(parsingError)")
|
||||
return "Error parsing template. \((parsingError as NSError).localizedFailureReason ?? parsingError.localizedDescription)"
|
||||
}
|
||||
}
|
||||
return "Error parsing template. \((parsingError as NSError).localizedFailureReason ?? parsingError.localizedDescription)"
|
||||
}
|
||||
|
||||
open func parsePageJSON() throws { }
|
||||
@ -200,7 +201,8 @@ import MVMCore
|
||||
}
|
||||
|
||||
guard modulesRequired.count == 0 else {
|
||||
if let errorObject = MVMCoreErrorObject(title: nil, message: MVMCoreGetterUtility.hardcodedString(withKey: HardcodedErrorCritical), messageToLog: modulesRequired.description, code: ErrorCode.requiredModuleNotPresent.rawValue, domain: ErrorDomainNative, location: MVMCoreLoadHandler.sharedGlobal()?.errorLocation(forRequest: loadObject!)) {
|
||||
if let loadObject = loadObject, let errorObject = MVMCoreLoadHandler.sharedGlobal()?.error(for: loadObject, withTitle:nil, message: MVMCoreGetterUtility.hardcodedString(withKey: HardcodedErrorCritical), code: ErrorCode.requiredModuleNotPresent.rawValue, domain: ErrorDomainNative) {
|
||||
errorObject.messageToLog = modulesRequired.description
|
||||
error.pointee = errorObject
|
||||
}
|
||||
return false
|
||||
@ -473,6 +475,14 @@ import MVMCore
|
||||
|
||||
open func handleAction(error: Error, model: ActionModelProtocol, additionalData: [AnyHashable : Any]?, delegateObject: DelegateObject?) {
|
||||
let errorObject = MVMCoreErrorObject.createErrorObject(for: error, location: MVMCoreActionHandler.getErrorLocation(with: delegateObject?.actionDelegate, actionType: model.actionType))!
|
||||
|
||||
switch (model) {
|
||||
case let model as ActionOpenPageModel:
|
||||
errorObject.silentError = model.background ?? false
|
||||
default:
|
||||
errorObject.silentError = false
|
||||
}
|
||||
|
||||
MVMCoreUIActionHandler.shared()?.defaultHandleActionError(errorObject, additionalData: additionalData)
|
||||
}
|
||||
|
||||
|
||||
@ -41,6 +41,7 @@ import SafariServices
|
||||
open override func defaultHandleActionError(_ error: MVMCoreErrorObject, additionalData: [AnyHashable : Any]?) {
|
||||
super.defaultHandleActionError(error, additionalData: additionalData)
|
||||
guard !error.silentError else { return }
|
||||
error.silentError = true // Silence if this error is triggered again. (Legacy action handler flow.)
|
||||
Task(priority: .userInitiated) { @MainActor in
|
||||
let alertObject = MVMCoreAlertObject.init(popupAlertWithError: error, isGreedy: false)!
|
||||
MVMCoreAlertHandler.shared()?.showAlert(with: alertObject)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user