dreymonde/Shallows

How to handle success in StorageProtocol set(value:forKey:completion:)

Closed this issue · 13 comments

Stupid question, but I'm finally getting around to updating all my Shallows-related code to support the latest SwiftPM version, and I'm not sure how to handle a successful result in set(value:forKey:completion:). All I really want is to be able to fire some function in the caller on success, but I'm not clear on using ShallowsResult<Void> in this context...
To clarify: my confusion is about implementing it in my custom Storage.

I think this actually relates to the Abort trap: 6 build errors I'm seeing (similar to here: #14 (comment)). I've seen a couple of posts in the wild that suggest these <unknown>:0: error: fatal error encountered while reading from module ... errors might be related to subclassing, so I'm thinking maybe it has to do with the custom Storage I'm using (not a subclass, I know, but maybe?). It worked for a long time, but needed some changes with the latest version of Shallows. I've attached the file, in case you can see anything obvious... and maybe you can help with the original question (since that code is in here)! ;-)
Any help would be hugely appreciated as I'm completed blocked right now.

RemoteStorage.swift.zip

Okay, I've verified that the RemoteStorage.swift class is the problem, and managed to work around it for now. Would be great to understand why it's a problem, but I'm up and running again.

Hi @jbmaxwell! I’ll take a look at your test project in a second

Sorry, not a test project actually, just the one file... but maybe you'll notice something right away.

@jbmaxwell maybe this

completion(fail(with: Error.remoteSaveError))

Can you try to instead use completion(.failure(Error.remoteSaveError))?

Who knows, maybe public global fail interferes with some other code

Also not entirely sure what you mean here:

All I really want is to be able to fire some function in the caller on success, but I'm not clear on using ShallowsResult in this context...

I assume you already had this implemented with the older version of Shallows? If yes, can you share that code with me so that I can help you with migrating it to the current version 🙂

same error using completion(.failure(Error.remoteSaveError))

@jbmaxwell got it. But the problem is with this line only? If you just comment it out, does the error go away?

Oh, about this:

                    // Not sure how to implement this...
//                    completion(succeed(with: ""))

You'll need to call completion(succeed(with: ()))

This is just a weird thing about how Swift.Result is implemented, because this is the Result<Void, Error>, you need to do .success(()) (or succeed(with: ()) with Shallows)

Ah, no sorry... I kind of hijacked my own thread! :) That line alone isn't the problem, afaik. I ended up moving forward by avoiding that file altogether. So I'm really not sure exactly what's wrong with it. One of our devs added this class, and I was able to workaround it by adding a function to another, more general "RemoteDataController" class I already had. So I did that just to keep moving forward.

geez... I'm about 99% certain I tried succeed(with: ())... ? (i.e., (Stuff) -> Void being synonymous with (Stuff) -> ()) I'll keep that it mind for next time.

Ah, no sorry... I kind of hijacked my own thread! :) That line alone isn't the problem, afaik. I ended up moving forward by avoiding that file altogether. So I'm really not sure exactly what's wrong with it. One of our devs added this class, and I was able to workaround it by adding a function to another, more general "RemoteDataController" class I already had. So I did that just to keep moving forward.

Damn, this is weird. I took a look at the file and not really sure what can be the problem. My best guess is that this is due to some naming collision, maybe Firebase has something called RemoteStorage internally, or something like that. Hard to tell. Great that you found a workaround by just removing the file! I'll close this for now but feel free to reopen if this happens again/you have a suggestion on why this was happening.