Crash due to SNMLModelFactory "try!" expression

Hello there,

We currently have a crash in prod when executing the following line:

let classificationRequest = try SNClassifySoundRequest(classifierIdentifier: .version1)

It appears to only happen on iOS 17+ and only when regaining audio focus after an interruption in a background state.

We are aware this call probably fails because it is happening from a background state - however - I would expect then that the SNClassifySoundRequest throws some kind of error since it is already an initializer that throws.

If it is possible for the call to fail under certain circumstances, then could SNMLModelFactory throw an error instead of using try! ? Full trace below:

SoundAnalysis/SNMLModelFactory.swift:112: Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=com.apple.CoreML Code=0 "Failed to build the model execution plan using a model architecture file '/System/Library/Frameworks/SoundAnalysis.framework/SNSoundClassifierVersion1Model.mlmodelc/model1/model.espresso.net' with error code: -1." UserInfo={NSLocalizedDescription=Failed to build the model execution plan using a model architecture file '/System/Library/Frameworks/SoundAnalysis.framework/SNSoundClassifierVersion1Model.mlmodelc/model1/model.espresso.net' with error code: -1.}

Some additional info: it appears to be specifically iOS 17.4 and above, so far on the following device models: iPhone XR, iPhone XS, iPhone XS Max

I'm able to reproduce 100% on an iPhone XR by making the SNClassifySoundRequest after locking the screen/putting app in background.

Crash due to SNMLModelFactory "try!" expression
 
 
Q