NSError and presentError:

  • So why is it that when the standard sheet for presentError: is
    displayed, it only ever uses NSLocalizedDescriptionKey and
    NSLocalizedRecoverySuggestionErrorKey? A lot of NSError objects don't
    have a value for NSLocalizedRecoverySuggestionErrorKey but they do
    have values for NSLocalizedFailureReasonErrorKey. Instead of using the
    failure reason, the sheet just doesn't show anything at all and only
    uses the description.

    It's pretty silly to only show _some_ of the information available,
    but the other silly thing is that if I want to use presentError: to
    display an NSError object, I have to supply the *reason* something
    failed with NSLocalizedRecoverySuggestionErrorKey so that the reason
    actually is displayed, despite the fact it's a failure reason and not
    a recovery suggestion.

    I could write my own method, and I suppose I probably should, but
    given there's existing methods and callbacks for the presentError:
    path, I wonder why it doesn't work as I think it should.

    --
    Seth Willits
  • On May 25, 2008, at 14:21, Seth Willits wrote:

    >
    > So why is it that when the standard sheet for presentError: is
    > displayed, it only ever uses NSLocalizedDescriptionKey and
    > NSLocalizedRecoverySuggestionErrorKey? A lot of NSError objects
    > don't have a value for NSLocalizedRecoverySuggestionErrorKey but
    > they do have values for NSLocalizedFailureReasonErrorKey. Instead of
    > using the failure reason, the sheet just doesn't show anything at
    > all and only uses the description.
    >
    > It's pretty silly to only show _some_ of the information available,
    > but the other silly thing is that if I want to use presentError: to
    > display an NSError object, I have to supply the *reason* something
    > failed with NSLocalizedRecoverySuggestionErrorKey so that the reason
    > actually is displayed, despite the fact it's a failure reason and
    > not a recovery suggestion.
    >
    > I could write my own method, and I suppose I probably should, but
    > given there's existing methods and callbacks for the presentError:
    > path, I wonder why it doesn't work as I think it should.
    >
    >
    > --
    > Seth Willits

    I asked the same question a few weeks ago, thinking along the same
    lines as you.

    The answer is actually in the error handling programming guide. It
    boils down to this:

    NSLocalizedDescriptionKey is intended to be "You can't A because B"
    NSLocalizedFailureReasonErrorKey intended to be "B"
    NSLocalizedRecoverySuggestionErrorKey is intended to be "Try C instead"

    Therefore, you don't need to display NSLocalizedFailureReasonErrorKey
    in a standard error alert because it's (supposed to be) part of
    NSLocalizedDescriptionKey already.
  • -localizedFailureReason is supposed to be the "why" part of -
    localizedDescription. Since it's already included in -
    localizedDescription, it is not shown again; otherwise you would get a
    repetition in the panel:

    Main message:  "The file <<file>> could not be copied you do not have
    appropriate access privileges."
    Secondary message: "You do not have appropriate access privileges."

    (In fact, if NSLocalizedDescriptionKey is not provided, but
    NSLocalizedFailureReasonErrorKey is, then -localizedDescription is
    manufactured from NSLocalizedFailureReasonErrorKey: "Operation could
    not be completed. << NSLocalizedFailureReasonErrorKey >>."  That would
    lead to even more repetition in the alert.)

    The secondary message is defined to come from -
    localizedRecoverySuggestion, so if you want a secondary message, then
    you need this to return a value.

    Ali

    On May 25, 2008, at 14:21 , Seth Willits wrote:

    >
    > So why is it that when the standard sheet for presentError: is
    > displayed, it only ever uses NSLocalizedDescriptionKey and
    > NSLocalizedRecoverySuggestionErrorKey? A lot of NSError objects
    > don't have a value for NSLocalizedRecoverySuggestionErrorKey but
    > they do have values for NSLocalizedFailureReasonErrorKey. Instead of
    > using the failure reason, the sheet just doesn't show anything at
    > all and only uses the description.
    >
    > It's pretty silly to only show _some_ of the information available,
    > but the other silly thing is that if I want to use presentError: to
    > display an NSError object, I have to supply the *reason* something
    > failed with NSLocalizedRecoverySuggestionErrorKey so that the reason
    > actually is displayed, despite the fact it's a failure reason and
    > not a recovery suggestion.
    >
    > I could write my own method, and I suppose I probably should, but
    > given there's existing methods and callbacks for the presentError:
    > path, I wonder why it doesn't work as I think it should.
    >
    >
    > --
    > Seth Willits
previous month may 2008 next month
MTWTFSS
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  
Go to today