NCKitError
Typed errors from all NCKit APIs.
Definitionโ
Swift
public enum NCKitError: Error, Sendable {
case missingModel(String)
case libraryInit
case badFrameLength(Int)
case cannotOpenInput
case cannotCreateOutput
case unsupportedFormat
case resampleFailed
}
Kotlin
sealed class NCKitException(message: String) : Exception(message) {
class MissingModel(val name: String) : NCKitException("Model file not found: $name")
class LibraryInit : NCKitException("df_create returned null")
class BadFrameLength(val length: Int) : NCKitException("Expected frame length 480, got $length")
class CannotOpenInput : NCKitException("Cannot open input file")
class CannotCreateOutput : NCKitException("Cannot create output file")
class UnsupportedFormat : NCKitException("No decodable audio track")
class ResampleFailed : NCKitException("Resample to 48 kHz mono failed")
}
Handle errorsโ
Swift
do {
let modelURL = try NCKitModelLocator.modelTarGzURL()
let processor = try NCKitProcessor(modelURL: modelURL)
try NCKitFileProcessor.processFile(
inputURL: inputURL,
outputURL: outputURL,
processor: processor
)
} catch NCKitError.missingModel(let name) {
// NCKit_model.tar.gz not embedded
} catch NCKitError.libraryInit {
// libdf failed to load model
} catch NCKitError.cannotOpenInput {
// input file not readable
} catch NCKitError.cannotCreateOutput {
// output file not writable
} catch NCKitError.unsupportedFormat {
// no decodable audio track
} catch NCKitError.resampleFailed {
// AVAudioConverter failed
} catch NCKitError.badFrameLength(let n) {
// wrong hop size for processFrame
} catch {
// other system errors
}
Kotlin
import com.fiveexceptions.nckit.NCKitException
try {
val cleanFile = DenoiseService.denoiseFile(context, inputFile)
} catch (_: NCKitException.MissingModel) {
// AAR not embedded correctly
} catch (_: NCKitException.LibraryInit) {
// Corrupt model or native library failure
} catch (_: NCKitException.CannotOpenInput) {
// Bad path or unreadable Uri copy
} catch (_: NCKitException.CannotCreateOutput) {
// Output directory not writable
} catch (_: NCKitException.UnsupportedFormat) {
// Unsupported audio format
} catch (_: NCKitException.ResampleFailed) {
// Resampler failure
} catch (_: NCKitException.BadFrameLength) {
// Wrong frame size for processFrame
} catch (e: Exception) {
Log.e("NCKit", "Unexpected: ${e.message}")
}
Casesโ
| Case | Source |
|---|---|
missingModel / MissingModel | NCKitModelLocator |
libraryInit / LibraryInit | NCKitProcessor init |
badFrameLength / BadFrameLength | NCKitProcessor.processFrame wrong buffer size (480 samples) |
cannotOpenInput / CannotOpenInput | NCKitFileProcessor.processFile |
cannotCreateOutput / CannotCreateOutput | NCKitFileProcessor.processFile |
unsupportedFormat / UnsupportedFormat | NCKitFileProcessor.processFile |
resampleFailed / ResampleFailed | NCKitFileProcessor.processFile |