Best practices for error handling #63
-
First of all, let me say that I really love GRDB and GRDBQuery - it makes dealing with persistence and writing database queries so much easier and more flexible than SwiftData! Now to my question: Do you have any recommendations or best practices for error handling in the Queryable implementations? I started with GRDBQuery 0.8.0 and found that errors in my queries (such as accessing the wrong columns) were simply ignored, which made debugging a bit difficult. To work around this, I wrote my publisher methods like this func publisher(in database: AppDatabase) -> AnyPublisher<[Customer], Never> {
return ValueObservation
.tracking(fetchValue(_:))
.publisher(in: database.reader, scheduling: .immediate)
.assertNoFailure() // assertNoFailure to make sure any SQL error causes a fatalError that will trigger an XCode breakpoint / sentry logging
.eraseToAnyPublisher()
} I am now in the process of migrating to GRDBQuery 0.10.0 and have seen that the Am I wrong in thinking that errors in a GRDBQuery should not normally occur unless I made a mistake when writing the query? Should I handle errors more gracefully than calling fatalError? Do you think it would be a good idea to add an Thanks for any tips you can give! :) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Hello @ChristophKaser, Thanks for migrating to 0.10.0, where apps can detect if an error happens. I'm not sure there is a good answer about handling them yet, because:
Since we're dealing with read-only queries, errors should generally be a programmer error (an invalid query that requires code to be changed), or an I/O error. I/O can always fail, unfortunately. I/O error can happen on locked device in the background, due to data protection, for example. I personally never had to deal with such errors, and this explains the somewhat dire state of error handling in GRDBQuery.
Maybe, in crucial views like the boot screen, you might want to check the |
Beta Was this translation helpful? Give feedback.
Hello @ChristophKaser,
Thanks for migrating to 0.10.0, where apps can detect if an error happens. I'm not sure there is a good answer about handling them yet, because:
Since we're dealing with read-only queries, errors should generally be a programmer error (an invalid query that requires code to be changed), or an I/O error. I/O can always fail, unfortunately. I/O error can happen on locked device in the background, due to data protection, for example.
I personally never had to deal with such errors, …