-
Notifications
You must be signed in to change notification settings - Fork 63
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
crash when initializing with an invalid model #26
Comments
As far as I'm aware, theres no way to catch fatally-throwing errors in Swift that originated from C. So I don't think a throwing initializer would be possible in this case. If you know of a way that I'm not aware of, please let me know. |
Hi, the error is passed using the return value, not an exception. Here is the fix that I am using in a fork: master...uni-industries:SwiftWhisper:master This allows checking the return value of the Would be happy to submit a PR if this direction is useful. |
Your branch looks good to me, though the tests and README will need to be updated to reflect it. If you'd like to do that as well, I'd be happy to merge it in a PR. |
I am running your fork yet Whisper is still nil: let whisper = Whisper(fromFileURL: recordedFile!) |
When
Whisper.init(fromFileURL)
is called with a file URL that is a file that exists, but not a valid model file, the error condition from the underlying whisper.cpp library is not handled.Specifically:
self.whisperContext = fileURL.relativePath.withCString { whisper_init_from_file($0) }
whisper_init_from_file
will returnnullptr
in this case. The attempted assignment produces the following error which crashes the program using the library.I'd like to add a check to this initializer so my program can catch and safely handle this case. In theory, my program could attempt to figure out if this was a valid model file, but this would involve re-implementing the detection code from whisper.cpp that I am trying to wrap. Letting that code that is already doing the error handling just pass the error through seems like a better arrangement.
Doing so would probably require changing the init signature to a throwing one or a fail-able one. I understand that this would involve a change in API here. Is there a way to handle this that would be likely to be accepted as a PR? Is there a more general plan for how to handle this sort of error case?
The text was updated successfully, but these errors were encountered: