tryReadBundleSampler function

Future<BundleSamplerRead> tryReadBundleSampler(
  1. String modelPath
)

readBundleSampler, with a file it cannot read or parse returned instead of thrown: a FileSystemException, a FormatException, or an ArgumentError (a RangeError, or a value no engine can sample with). Any other error is a bug in this reader and is thrown.

Implementation

Future<BundleSamplerRead> tryReadBundleSampler(String modelPath) async {
  try {
    final metadata = await readBundleMetadata(modelPath);
    return BundleSamplerRead(
      metadata.sampler,
      declaresChannel: metadata.declaresChannel,
    );
  } on Object catch (e, st) {
    if (e is! FileSystemException &&
        e is! FormatException &&
        e is! ArgumentError) {
      rethrow;
    }
    return BundleSamplerRead.failed('${e.runtimeType}: $e\n$st');
  }
}