session icon indicating copy to clipboard operation
session copied to clipboard

Question: The signatures of the Store interface methods

Open rumyantseva opened this issue 8 years ago • 1 comments

I have a question about dealing with errors. The signatures of the Store interface methods don't have error as return value. What is the best way to deal with errors in this case?

For example, if I use database, in case of error I'd like to return error to the part of code which asked for the method. The Store interface methods don't give me this possibility, so the only way is to return nil and log error. But in some cases I'd like to tell user that something went wrong instead of pretending that session was saved.

For example, I want something like this:

err := session.Add(sessionData, c.Writer)
if err != nil {
  // return 500 error
}

But I have only this:

session.Add(sessionData, c.Writer)
// How can I understand that something went wrong?

Do you think if it is possible to add error to the signatures in the next major version of the library?

rumyantseva avatar May 29 '17 07:05 rumyantseva

Good idea, it might have been an overlook from my part when designing the API.

Similarly, if we proceed to add an error return value too to the Store methods, we should do the same with the Manager interface (a Manager implementation uses a Store implementation under the hood, and it is reasonable / makes sense to "delegate" the errors returned by the used Store).

icza avatar May 29 '17 08:05 icza