Is there some way to get a string description of CFStreamError?

1.5k Views Asked by At

I am using an API which has handed me a CFStreamError (which is supposedly deprecated, but Apple themselves obviously don't care.)

I know some of the values and I could certainly write multiple nested switch statements to convert all the values I know into strings, but there will be values I don't know.

Isn't there some convenient way to get an error message out? I don't care whether it's localised or not because it will only end up in our logs anyway.

2

There are 2 best solutions below

5
cacau On

The 'old', pre-NSError way of handling errors usually involved return codes that were supposed to be used internally by the application (i.e. the developer) and not for presenting to the user.

With newer APIs the NSError returned actually contains information that an be presented to the user (if appropriate).

As for the CFStreamError -
There's an entry on CocoaDev on making CFStreamError human-readable:

http://cocoadev.com/CFStreamErrorCodes

Basically it involves manually checking the various error domains from CFStream Error Domain Constants.

A bit more information from Developer Technical Support can be found in this post on the Macnetworkprog mailing list.

0
nmr On

This works for POSIX domain errors:

            if (err.domain == kCFStreamErrorDomainPOSIX) {
                DLog("POSIX err: %s", strerror(err.error));
            } else {
                DLog("domain: %d, value: %d", err.domain, err.error);
            }

E.g.:

2020-01-31 09:58:02.996603-0800 blah void CFWriteStreamCB(CFWriteStreamRef _Null_unspecified, CFStreamEventType, void * _Null_unspecified):26 POSIX err: Operation timed out