-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Related: * `TODO:2023-03-27-23-55-09` Refactor: Re-write `RNIModalView` error creation and handling.
- Loading branch information
1 parent
a6b905e
commit c769f6f
Showing
9 changed files
with
231 additions
and
135 deletions.
There are no files selected for viewing
99 changes: 99 additions & 0 deletions
99
ios/src_library/React Native/RNIError/RNIBaseError+Helpers.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// | ||
// RNIBaseError+Helpers.swift | ||
// react-native-ios-modal | ||
// | ||
// Created by Dominic Go on 5/12/23. | ||
// | ||
|
||
import Foundation | ||
|
||
extension RNIBaseError { | ||
|
||
public var errorMessage: String { | ||
var message = "message: \(self.message ?? "N/A")"; | ||
|
||
#if DEBUG | ||
message += " - debugMessage: \(self.debugMessage ?? "N/A")"; | ||
#endif | ||
|
||
if let fileID = self.fileID { | ||
message += "- fileID: \(fileID)"; | ||
}; | ||
|
||
if let functionName = self.functionName { | ||
message += "- functionName: \(functionName)"; | ||
}; | ||
|
||
if let lineNumber = self.lineNumber { | ||
message += "- lineNumber: \(lineNumber)"; | ||
}; | ||
|
||
return message; | ||
}; | ||
|
||
public init( | ||
code: ErrorCode, | ||
message: String? = nil, | ||
debugMessage: String? = nil, | ||
debugData: Dictionary<String, Any>? = nil, | ||
fileID: String? = #fileID, | ||
functionName: String? = #function, | ||
lineNumber: Int? = #line | ||
) { | ||
self.init( | ||
code: code, | ||
message: message, | ||
debugMessage: debugMessage | ||
); | ||
|
||
self.fileID = fileID; | ||
self.functionName = functionName; | ||
self.lineNumber = lineNumber; | ||
}; | ||
|
||
public mutating func setDebugValues( | ||
fileID: String = #fileID, | ||
functionName: String = #function, | ||
lineNumber: Int = #line | ||
) { | ||
self.fileID = fileID; | ||
self.functionName = functionName; | ||
self.lineNumber = lineNumber; | ||
}; | ||
|
||
public mutating func addDebugData(_ nextDebugData: Dictionary<String, Any>){ | ||
guard let prevDebugData = self.debugData else { | ||
self.debugData = nextDebugData; | ||
return; | ||
}; | ||
|
||
self.debugData = prevDebugData.merging(nextDebugData) { (_, new) in new }; | ||
}; | ||
}; | ||
|
||
extension RNIBaseError where Self: RNIDictionarySynthesizable { | ||
|
||
public var asNSError: NSError? { | ||
|
||
let errorCode = self.code.errorCode ?? | ||
RNIGenericErrorCode.unspecified.errorCode; | ||
|
||
guard let errorCode = errorCode else { return nil }; | ||
|
||
return NSError( | ||
domain: Self.domain, | ||
code: errorCode, | ||
userInfo: self.synthesizedJSDictionary | ||
); | ||
}; | ||
|
||
public func invokePromiseRejectBlock( | ||
_ block: @escaping RCTPromiseRejectBlock | ||
) { | ||
block( | ||
/* code */ self.code.description, | ||
/* message */ self.errorMessage, | ||
/* error */ self.asNSError | ||
); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// RNIError.swift | ||
// react-native-ios-modal | ||
// | ||
// Created by Dominic Go on 5/12/23. | ||
// | ||
|
||
import Foundation | ||
|
||
public typealias RNIError = | ||
RNIBaseError & RNIDictionarySynthesizable; | ||
|
||
public typealias RNIErrorCode = | ||
CustomStringConvertible | ||
& CaseIterable | ||
& Equatable | ||
& RNIErrorCodeDefaultable | ||
& RNIErrorCodeSynthesizable; |
70 changes: 70 additions & 0 deletions
70
ios/src_library/React Native/RNIError/RNIErrorCodeDefaultable.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// | ||
// RNIGenericErrorDefaultable.swift | ||
// react-native-ios-utilities | ||
// | ||
// Created by Dominic Go on 8/28/22. | ||
// | ||
|
||
import Foundation | ||
|
||
public protocol RNIErrorCodeDefaultable { | ||
|
||
static var runtimeError : Self { get }; | ||
static var libraryError : Self { get }; | ||
static var reactError : Self { get }; | ||
static var unknownError : Self { get }; | ||
static var invalidArgument: Self { get }; | ||
static var outOfBounds : Self { get }; | ||
static var invalidReactTag: Self { get }; | ||
static var nilValue : Self { get }; | ||
}; | ||
|
||
// MARK: - Default | ||
// --------------- | ||
|
||
public extension RNIErrorCodeDefaultable { | ||
|
||
static var runtimeError: Self { | ||
Self.runtimeError | ||
}; | ||
|
||
static var libraryError: Self { | ||
Self.libraryError | ||
}; | ||
|
||
static var reactError: Self { | ||
Self.reactError | ||
}; | ||
|
||
static var unknownError: Self { | ||
Self.unknownError | ||
}; | ||
|
||
static var invalidArgument: Self { | ||
Self.invalidArgument | ||
}; | ||
|
||
static var outOfBounds: Self { | ||
Self.outOfBounds | ||
}; | ||
|
||
static var invalidReactTag: Self { | ||
Self.invalidReactTag | ||
}; | ||
|
||
static var nilValue: Self { | ||
Self.nilValue | ||
}; | ||
}; | ||
|
||
// MARK: - Helpers | ||
// --------------- | ||
|
||
extension RNIErrorCodeDefaultable where Self: RawRepresentable<String> { | ||
|
||
public var description: String { | ||
self.rawValue; | ||
}; | ||
}; | ||
|
||
|
24 changes: 24 additions & 0 deletions
24
ios/src_library/React Native/RNIError/RNIErrorCodeSynthesizable.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// RNIErrorCodeSynthesizable.swift | ||
// react-native-ios-modal | ||
// | ||
// Created by Dominic Go on 5/12/23. | ||
// | ||
|
||
import Foundation | ||
|
||
public protocol RNIErrorCodeSynthesizable { | ||
var errorCode: Int? { get }; | ||
} | ||
|
||
extension RNIErrorCodeSynthesizable where Self: CaseIterable & Equatable { | ||
|
||
public var errorCode: Int? { | ||
let match = Self.allCases.enumerated().first { _, value in | ||
value == self | ||
} | ||
|
||
guard let offset = match?.offset else { return nil }; | ||
return offset * -1; | ||
}; | ||
}; |
25 changes: 0 additions & 25 deletions
25
ios/src_library/React Native/RNIError/RNIGenericError.swift
This file was deleted.
Oops, something went wrong.
9 changes: 4 additions & 5 deletions
9
ios/src_library/React Native/RNIError/RNIGenericErrorCode.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,15 @@ | ||
// | ||
// RNIGenericErrorCode.swift | ||
// react-native-ios-utilities | ||
// react-native-ios-modal | ||
// | ||
// Created by Dominic Go on 4/21/22. | ||
// Created by Dominic Go on 5/12/23. | ||
// | ||
|
||
import Foundation | ||
|
||
|
||
public enum RNIGenericErrorCode: | ||
String, Codable, CaseIterable, RNIGenericErrorDefaultable { | ||
enum RNIGenericErrorCode: | ||
String, CaseIterable, RNIErrorCodeDefaultable, RNIErrorCodeSynthesizable { | ||
|
||
// placeholder | ||
case unspecified; | ||
}; |
42 changes: 0 additions & 42 deletions
42
ios/src_library/React Native/RNIError/RNIGenericErrorDefaultable+Default.swift
This file was deleted.
Oops, something went wrong.
20 changes: 0 additions & 20 deletions
20
ios/src_library/React Native/RNIError/RNIGenericErrorDefaultable.swift
This file was deleted.
Oops, something went wrong.