-
Notifications
You must be signed in to change notification settings - Fork 459
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
Why is this a force unwrap ? My app just crashed #1730
Comments
Complete Stack Trace zaraapp-1 | swift-runtime: failed to suspend thread 60890 while processing a crash; backtraces will be missing information |
An error on that line implies the runtime generated invalid utf8. Do you have a repo of how you got the runtime to do that? |
(As a sidebar, we can remove the force unwrap by replacing this with |
I am unable to get it to crash again running the same command, How do you want the code represented? I cant share the whole repo as its confidential but I cant send snippets? public func sendJson<T>(_ value: T) throws where T : SwiftProtobuf.Message {
self.request.logger.info("Sending JSON: \(value)")
self.request.logger.info("Sending JSON: \(value.textFormatString())")
if self.acceptBinary() {
response?.headers.contentType = .init(type: "application", subType: "protobuf")
response?.body = .init(data: try value.serializedData())
} else {
response?.headers.contentType = .json
response?.body = .init(string: try value.jsonString())
}
self.completed()
} |
@adirburke I doubt the problem is your code per say, it's is going to be a specific field (or set of fields) being set to specific values that causes the problem. So to catch this you'd likely have to add some extra code to catch this and then start to inspect how the message is configure to figure out the exact problem. |
Avoids the force unwraps that were needed before. From the comment in apple#1730 (comment).
Avoids the force unwraps that were needed before. From the comment in apple#1730 (comment).
@adirburke -- Can you print out There's some content in your message that we're failing to correctly convert to JSON and I'd like to track down exactly what that is. There are a few cases where we genuinely cannot produce correct JSON, but all such cases should already be throwing errors instead of producing invalid text. I fear that fixing this force-unwrap will hide that other bug. |
@tbkka - Sadly, that's probably going to fail also, as it traces back to
|
I'll send through the proto file and the generated code when I'm next at my laptop Would that help ? Not sure where to go from here . I had the same thought of doing a print before the convert to see but you pointed out it has a force unwrap too Let me know how I can help find the bug |
Given that an error handling path exists for us, a useful step might be to amend this code to throw an error in the nil return case. At least that avoids the crash. We could elect to crash in debug mode if we wanted to prompt issues to be filed for diagnostic purposes. |
That might tells us what subset of field types are at play, but the real question is what data got into one of those fields that we failed to serialize to json correctly. Somehow catching those specifics is likely the important details. Actually, relooking at you code snippet (#1730 (comment)), I'm realizing something strange. The snippet says there was a call to So I think that implies only two possible things:
|
swift-protobuf/Sources/SwiftProtobuf/Message+JSONAdditions.swift
Line 35 in 4782e2f
I just had a
Swift runtime failure: Unexpectedly found nil while unwrapping an Optional value
The function is throwing couldn't you throw a nil error instead of force-unwrap
The text was updated successfully, but these errors were encountered: