3

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.

cacau
  • 3,606
  • 3
  • 21
  • 42
Hakanai
  • 12,010
  • 10
  • 62
  • 132

2 Answers2

0

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.

cacau
  • 3,606
  • 3
  • 21
  • 42
  • That is what I feared... so basically to get a string out of it I would have to also add nested switch statements which go through every error code in every header and return a different string... that's too much work for this project, so I would probably just return the generic "domain X, error X" string. :/ – Hakanai Mar 13 '14 at 00:42
  • In most cases users wouldn't be able to solve the problem by themselves even when knowing the exact error message - assuming a medium skilled Mac user and not a target audience of network admins – cacau Mar 13 '14 at 14:57
  • I suppose you're also going to say that our support staff shouldn't be able to see the error message either? Or that they should waste their time looking it up from a huge list of error messages spread across multiple files? :/ – Hakanai Mar 14 '14 at 00:42
  • Well, it all depends on your use case - if support will be able to suggest specific ways to tackle the problem that information might be valuable and should be included.. – cacau Mar 14 '14 at 07:37
  • Another useful post added (looks like more manual work to get human-readable errors, though) – cacau Mar 14 '14 at 07:42
0

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

nmr
  • 16,625
  • 10
  • 53
  • 67