"zero length data" error

I had a customer feedback about a "zero length data" error which was captured using an exception handler and displayed using NSAlert.

My app employs [NSURLSession dataTaskWithURL:] to download XML and image data.

But I got no idea what it is about. I assume it's related to NSData, but this error never happened before (for years).

Does anyone have any idea about the source of this error?

Answered by imneo in 778877022

Anyway, I found out the cause.

The error is thrown when initializing XMLDocument with an empty string:

let xd = try XMLDocument(xmlString: "")

captured using an exception handler and displayed using NSAlert.

Don't do that; let the app crash, and then look at the crash logs that Apple will send you. These will include a stack trace so you'll have some chance of identifying the cause.

If you really want to trap fatal exceptions yourself, include more diagnostics.

Accepted Answer

Anyway, I found out the cause.

The error is thrown when initializing XMLDocument with an empty string:

let xd = try XMLDocument(xmlString: "")
"zero length data" error
 
 
Q