-
Notifications
You must be signed in to change notification settings - Fork 109
Storage hardening; Add error handling capabilities. #163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
b2f62a1
Storage hardening; Expose monitoring capabilities.
bsneed 9e85e20
Updated header
bsneed 81cc70b
Trying to fix CI.
bsneed 436eb5d
Disabled logger tests; Will remove in the future.
bsneed 5aa9781
fix package.resolved
bsneed cb6dc7f
Fix package resolved.
bsneed 250a157
And again ...
bsneed e7c06ed
Account for lack of URLProtocol in Linux
bsneed c4c8172
Refactored ErrorHandling to be more global applicable.
bsneed e6e43c7
Merge remote-tracking branch 'origin/main' into bsneed/storage_fixes
bsneed 7a9bb21
Fixed xcodeproj
bsneed 82faf28
Fixed merge issues.
bsneed 36d981e
Removed accidental commit of example changes.
bsneed 13cf429
Renamed `hardStop` to `fatal` as it's more descriptive.
bsneed 8a89b3d
Fixed up callpoints.
bsneed 0d34e46
Fixed watchOS tests.
bsneed File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
16 changes: 0 additions & 16 deletions
16
Segment.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
Segment.xcodeproj/xcshareddata/xcschemes/Segment-Package.xcscheme
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,79 @@ | ||
| // | ||
| // Errors.swift | ||
| // | ||
| // | ||
| // Created by Brandon Sneed on 10/20/22. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| public enum AnalyticsError: Error { | ||
| case storageUnableToCreate(String) | ||
| case storageUnableToWrite(String) | ||
| case storageUnableToRename(String) | ||
| case storageUnableToOpen(String) | ||
| case storageInvalid(String) | ||
| case storageUnknown(Error) | ||
|
|
||
| case networkUnexpectedHTTPCode(Int) | ||
| case networkServerLimited(Int) | ||
| case networkServerRejected(Int) | ||
| case networkUnknown(Error) | ||
| case networkInvalidData | ||
|
|
||
| case jsonUnableToSerialize(Error) | ||
| case jsonUnableToDeserialize(Error) | ||
| case jsonUnknown(Error) | ||
|
|
||
| case pluginError(Error) | ||
| } | ||
|
|
||
| extension Analytics { | ||
| /// Tries to convert known error types to AnalyticsError. | ||
| static internal func translate(error: Error) -> Error { | ||
| if let e = error as? OutputFileStream.OutputStreamError { | ||
| switch e { | ||
| case .invalidPath(let path): | ||
| return AnalyticsError.storageInvalid(path) | ||
| case .unableToCreate(let path): | ||
| return AnalyticsError.storageUnableToCreate(path) | ||
| case .unableToOpen(let path): | ||
| return AnalyticsError.storageUnableToOpen(path) | ||
| case .unableToWrite(let path): | ||
| return AnalyticsError.storageUnableToWrite(path) | ||
| } | ||
| } | ||
|
|
||
| if let e = error as? JSON.JSONError { | ||
| switch e { | ||
| case .incorrectType: | ||
| return AnalyticsError.jsonUnableToDeserialize(e) | ||
| case .nonJSONType: | ||
| return AnalyticsError.jsonUnableToDeserialize(e) | ||
| case .unknown: | ||
| return AnalyticsError.jsonUnknown(e) | ||
| } | ||
| } | ||
| return error | ||
| } | ||
|
|
||
| /// Reports an internal error to the user-defined error handler. | ||
| public func reportInternalError(_ error: Error, fatal: Bool = false) { | ||
| let translatedError = Self.translate(error: error) | ||
| configuration.values.errorHandler?(translatedError) | ||
| Self.segmentLog(message: "An internal error occurred: \(translatedError)", kind: .error) | ||
| if fatal { | ||
| exceptionFailure("A critical error occurred: \(translatedError)") | ||
| } | ||
| } | ||
|
|
||
| static public func reportInternalError(_ error: Error, fatal: Bool = false) { | ||
| // we don't have an instance of analytics to call to get our error handler, | ||
| // but we can at least report the message to the console. | ||
| let translatedError = Self.translate(error: error) | ||
| Self.segmentLog(message: "An internal error occurred: \(translatedError)", kind: .error) | ||
| if fatal { | ||
| exceptionFailure("A critical error occurred: \(translatedError)") | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious as to why it returns the
Configuration?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The config methods are all chainable and this continues that. Makes is so you can do ...
.. instead of having to create an instance and then set them all afterwards.