Widget crashing with *** Terminating app due to uncaught exception 'NSFileHandleOperationException', reason: '*** -[NSConcreteFileHandle fileDescriptor]: Invalid argument'

Anyone know how to solve this error?
I have no idea why it's happening because I'm not using NSFileHandle or anything like that at all, my widget is super simple: makes an API call, processes it with SwiftyJSON, and displays very simple data.

Thanks in advance
  • Any updates on this error message? Running into the same exact error and have no clue how to resolve. I double checked that I am not calling completion multiple times.

Add a Comment

Replies

I think this could happen when you call completion 2 times.


I have got this crash too, but it happened when scroll this widget in widget install menu.
This description of crash is not informative at all! @Apple
Thanks @boerni.

In our testing, it definitely causes an exception if you call completion more than once, but it seems to be a little different - "No such file or directory" instead of "Invalid Argument".

Code Block
* Terminating app due to uncaught exception 'NSFileHandleOperationException', reason: '* -[NSConcreteFileHandle fileDescriptor]: No such file or directory'
terminating with uncaught exception of type NSException


Having said that, I'll see if I can find any ways that ours could possibly call completion more than once and see if that helps.
Hello everyone. We have something similar, a crash in WidgetExtension. Report says:

Code Block
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Triggered by Thread: 0
Last Exception Backtrace:
0 CoreFoundation 0x1b00fc878 exceptionPreprocess + 220 (NSException.m:199)
1 libobjc.A.dylib 0x1c4652c50 objc_exception_throw + 60 (objc-exception.mm:565)
2 Foundation 0x1b13ea7f4 _NSFileHandleRaiseOperationExceptionWhileReading + 280 (NSFileHandle.m:71)
3 Foundation 0x1b13ea25c _NSFileHandleRaiseOperationException + 20 (NSFileHandle.m:75)
4 Foundation 0x1b13a9d58 -[NSConcreteFileHandle fileDescriptor] + 56 (NSFileHandle.m:640)
5 SwiftUI 0x1b6bff814 FileArchiveWriter.appendBytes(_:size:) + 52 (ArchiveData.swift:160)
6 SwiftUI 0x1b6bffa88 FileArchiveWriter.append<A>(_:) + 200 (ArchiveData.swift:154)
7 SwiftUI 0x1b6bfef04 ArchiveWriter.addAttachment(data:) + 372 (ArchiveData.swift:79)
8 SwiftUI 0x1b6c010bc Encoder.encodeAttachedValue<A>(key:data:) + 460 (ArchiveData.swift:362)
9 SwiftUI 0x1b6fa07ac CodableCGImage.encode(to:) + 136 (CodableImage.swift:111)
10 SwiftUI 0x1b6fa0c64 protocol witness for Encodable.encode(to:) in conformance CodableCGImage + 20 (<compiler-generated>:0)
11 libswiftCore.dylib 0x1b3ffbcd8 dispatch thunk of Encodable.encode(to:) + 28
12 libswiftFoundation.dylib 0x1b3b94b64 PlistEncoder.box_<A>(_:) + 340 (PlistEncoder.swift:523)
13 libswiftFoundation.dylib 0x1b3b95fb8 _PlistKeyedEncodingContainer.encode<A>(_:forKey:) + 492 (PlistEncoder.swift:508)
14 libswiftFoundation.dylib 0x1b3b97184 protocol witness for KeyedEncodingContainerProtocol.encode<A>(_:forKey:) in conformance _PlistKeyedEncodingContainer<A> + 32 (<compiler-generated>:0)
15 libswiftCore.dylib 0x1b3d17048 _KeyedEncodingContainerBox.encode<A, B>(_:forKey:) + 404 (Codable.swift:3732)
16 libswiftCore.dylib 0x1b3d0b1ac KeyedEncodingContainer.encode<A>(_:forKey:) + 52 (Codable.swift:677)
17 SwiftUI 0x1b6a2594c GraphicsImage.encode(to:) + 392 (GraphicsImage.swift:124)
18 SwiftUI 0x1b6a26294 protocol witness for Encodable.encode(to:) in conformance GraphicsImage + 16 (<compiler-generated>:0)
19 libswiftCore.dylib 0x1b3ffbcd8 dispatch thunk of Encodable.encode(to:) + 28
...


We are still investigating this crash. We definitely don't see our code at all.

Any updates on this error message? Running into the same exact error and have no clue how to resolve. I double checked that I am not calling completion multiple times.

Check you aren't calling the completion handler on a background thread. That solved my issue...