Nick Schaefer
Nick Schaefer
CCConvex Community
Created by Nick Schaefer on 3/1/2025 in #support-community
React Native Offline App Behavior
I'm build an iOS app with Expo / React Native. I am using Expo Go at least for now (honestly this could be my issue...). Testing on an iPhone. What's the default behavior for Convex functions when network connection is lost? I was expecting an error, but instead what happened was nothing until I reconnected to the network and it processed all the requests. Is this normal? I was hoping it would throw an error or something so I could handle it, instead it created a buggy UI experience. I'll have to make a dev build to really test this, but just wanted to see if anyone knew the expected behavior here. Thanks.
3 replies
CCConvex Community
Created by Nick Schaefer on 12/23/2024 in #support-community
Request for better Swift Error Handling
As I've been setting up my app in Swift, I've been encountering this error:
Thread 3: Fatal error: 'try!' expression unexpectedly raised an error: Swift.DecodingError.typeMismatch(Swift.String, Swift.DecodingError.Context(codingPath: [], debugDescription: "Expected to decode String but found a dictionary instead.", underlyingError: nil))
Thread 3: Fatal error: 'try!' expression unexpectedly raised an error: Swift.DecodingError.typeMismatch(Swift.String, Swift.DecodingError.Context(codingPath: [], debugDescription: "Expected to decode String but found a dictionary instead.", underlyingError: nil))
In this internal Convex code:
func callForResult<T: Decodable>(
name: String, args: [String: ConvexEncodable?]? = nil, remoteCall: RemoteCall
)
async throws -> T
{
let rawResult = try await remoteCall(
name,
args?.mapValues({ v in
try v?.convexEncode() ?? "null"
}) ?? [:])
return try! JSONDecoder().decode(T.self, from: Data(rawResult.utf8)) // here
}
func callForResult<T: Decodable>(
name: String, args: [String: ConvexEncodable?]? = nil, remoteCall: RemoteCall
)
async throws -> T
{
let rawResult = try await remoteCall(
name,
args?.mapValues({ v in
try v?.convexEncode() ?? "null"
}) ?? [:])
return try! JSONDecoder().decode(T.self, from: Data(rawResult.utf8)) // here
}
At first I discovered it was because I was naming my Convex mutation name with a dot instead of a colon try await convex.mutation("~~items.create~~item:create", with: ["name": name]). But now I'm experiencing the same error for another completely different reason. Wrapping the mutation/action in a do/try/catch does not catch this error either - it crashes the app every time. I may follow this up with my latest issue if I don't solve it soon, but I would appreciate some better error handling here if possible. Thanks 🙂
8 replies