@craft-native/ios 0.0.222 → 0.0.224

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@craft-native/ios",
3
- "version": "0.0.222",
3
+ "version": "0.0.224",
4
4
  "homepage": "https://github.com/craft-native/craft/tree/main/packages/ios#readme",
5
5
  "repository": {
6
6
  "type": "git",
@@ -794,7 +794,7 @@ enum CraftNativeActions {
794
794
  return
795
795
  }
796
796
  let code = (error as? URLError)?.code == .timedOut ? "TIMEOUT" : "NETWORK_ERROR"
797
- CraftNativeMedia.finish(address, failure(code, error.localizedDescription))
797
+ CraftNativeMedia.finish(address, failure(CraftNativeMedia.errorCode(error, fallback: code), error.localizedDescription))
798
798
  return
799
799
  }
800
800
  guard let http = response as? HTTPURLResponse, let location else {
@@ -492,6 +492,20 @@ enum CraftNativeFiles {
492
492
  // JavaScript. The screen decides what to keep (`keep`) and what to drop
493
493
  // (`prune`); nothing is evicted behind its back.
494
494
  enum CraftNativeMedia {
495
+ /// Foundation often wraps ENOSPC inside a URL or Cocoa file error.
496
+ static func errorCode(_ error: Error, fallback: String) -> String {
497
+ var cause: NSError? = error as NSError
498
+ var seen = Set<ObjectIdentifier>()
499
+ while let current = cause, seen.insert(ObjectIdentifier(current)).inserted {
500
+ if (current.domain == NSCocoaErrorDomain && current.code == NSFileWriteOutOfSpaceError)
501
+ || (current.domain == NSPOSIXErrorDomain && current.code == Int(POSIXError.Code.ENOSPC.rawValue)) {
502
+ return "NO_SPACE"
503
+ }
504
+ cause = current.userInfo[NSUnderlyingErrorKey] as? NSError
505
+ }
506
+ return fallback
507
+ }
508
+
495
509
  static var root: URL {
496
510
  let base = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).first
497
511
  ?? FileManager.default.temporaryDirectory
@@ -578,7 +592,7 @@ enum CraftNativeMedia {
578
592
  return .success(describe(address, target))
579
593
  }
580
594
  catch {
581
- return .failure(CraftNativeActionError(code: "IO_ERROR", message: "media.keep could not store the file: \(error.localizedDescription)"))
595
+ return .failure(CraftNativeActionError(code: errorCode(error, fallback: "IO_ERROR"), message: "media.keep could not store the file: \(error.localizedDescription)"))
582
596
  }
583
597
  }
584
598