Infer error domain and code from localizedDescription

I have been bitten by this repeatedly so I am finally going to ask: Is there a way to infer an error from its localizedDescription only?

It sometimes happens that a user reaches out for support with just a localized error message, but no error code or error domain and it is really hard to correctly guess what the non-localized description may have been in order to search for it.

For example I know from experience that "Der eingegebene Benutzername oder das Passwort ist ungültig." is the German localization of "The user name or passphrase you entered is not correct." which in turn is errSecAuthFailed (aka. -25293). It would be really helpful to be able to just look this up somewhere...

Answered by DTS Engineer in 802846022
Is there a way to infer an error from its localizedDescription only?

No.

In some domains it’s possible to figure this out by creating an error with a specific code in that domain and then asking for its localised description. However, that won’t work in general because not all domains are wired up to provide the error based on just the code; rather, the code that creates the error provides the localised description at the point of creation.

If your app displays localised errors there are a few common things you can do to help out here:

  • Change the display code to include the error domain and code.

  • Or add a small ‘copy description’ button, and include the domain and code there.

  • Or log the domain and code and provide the user an easy way to access that log.


Oh, and I just noticed that you tagged this thread with Security. If that’s your main focus, some rummaging around in Darwin will uncover /System/Library/Frameworks/Security.framework/Versions/A/Resources/SecErrorMessages.loctable.

WARNING This, like anything else you find in Darwin, is an implementation detail. It’s fine to use it in your support process, but don’t use it in software that you ship to a wide range of users.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Accepted Answer
Is there a way to infer an error from its localizedDescription only?

No.

In some domains it’s possible to figure this out by creating an error with a specific code in that domain and then asking for its localised description. However, that won’t work in general because not all domains are wired up to provide the error based on just the code; rather, the code that creates the error provides the localised description at the point of creation.

If your app displays localised errors there are a few common things you can do to help out here:

  • Change the display code to include the error domain and code.

  • Or add a small ‘copy description’ button, and include the domain and code there.

  • Or log the domain and code and provide the user an easy way to access that log.


Oh, and I just noticed that you tagged this thread with Security. If that’s your main focus, some rummaging around in Darwin will uncover /System/Library/Frameworks/Security.framework/Versions/A/Resources/SecErrorMessages.loctable.

WARNING This, like anything else you find in Darwin, is an implementation detail. It’s fine to use it in your support process, but don’t use it in software that you ship to a wide range of users.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Thanks Quinn, the loctable was basically what I was looking for.

Infer error domain and code from localizedDescription
 
 
Q