Skip to content
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

Storage hardening; Add error handling capabilities. #163

Merged
merged 16 commits into from Oct 25, 2022
Merged

Conversation

bsneed
Copy link
Contributor

@bsneed bsneed commented Oct 15, 2022

  • Added OutputFileStream class to shield us a little from Swift's back-and-forth/deprecations on FileHandle.
  • Added storage stress tests to test suite.
  • Improved some existing test cases.
  • Added errorHandler to configuration so developer can receive errors we see internally.

Affects #154 and #162.

@bsneed bsneed changed the title Storage hardening; Expose monitoring capabilities. Storage hardening; Add error handling capabilities. Oct 21, 2022
Copy link

@oscb oscb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few questions and small comments, but overall I think this looks good!

@@ -95,5 +99,16 @@ public extension Configuration {
values.cdnHost = value
return self
}

@discardableResult
func errorHandler(_ value: @escaping (Error) -> Void) -> Configuration {
Copy link

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 ?

Copy link
Contributor Author

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 ...

let analytics = Configuration(writeKey: "1234")
                         .trackLifecycleEvents(true)
                         .apiHost("eu1.segmentapi.com")
                         .whateverElse()

.. instead of having to create an instance and then set them all afterwards.

}

/// Reports an internal error to the user-defined error handler.
public func reportInternalError(_ error: Error, hardStop: Bool = false) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe critical instead of hardStop sounds more exception-like?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

named it fatal instead as it seemed more descriptive of what was going to happen, ie: YOUR APP WILL DIE.

// flushInterval and flushAt can be modified post initialization
analytics.store.subscribe(self, initialState: true) { [weak self] (state: System) in
guard let self = self else { return }
self.flushTimer = QueueTimer(interval: state.configuration.values.flushInterval) { [weak self] in
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how this works in Swift but wouldn't it also have to cancel the previous timer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QueueTimer is a wrapper on a dispatch source timer. Cancel is handled in dealloc.

@bsneed bsneed merged commit b1ed208 into main Oct 25, 2022
@bsneed bsneed deleted the bsneed/storage_fixes branch October 25, 2022 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants