I have created a custom Xcode editor extension that can fail to run if certain conditions have not been met.
Specifically, it's a Sort Lines command and will refuse to run if there is more than one selection, or if the selection has fewer than two lines.
I have defined an Error-conforming enum to define my errors that also conforms to LocalizedError.
enum CommandError: Error, LocalizedError
{
case notEnoughLines
case tooManySelections
public var errorDescription: String?
{
switch self
{
case .notEnoughLines: return NSLocalizedString("Not enough lines to sort", comment: "notEnoughLines")
case .tooManySelections: return NSLocalizedString("Too many selections", comment: "tooManySelections")
}
}
}
In my perform(with:completionHandler:) method I call the completion handler with one of the errors as appropriate:
...
if invocation.buffer.selections.count > 1
{
completionHandler(CommandError.tooManySelections)
return
}
...
I am expecting the text of the error ("Too many selections") to be displayed. Instead, the error is displayed as:
The operation couldn't be completed. (Ext01.SortLinesCommand.CommandError error 1.)
Am I doing this incorrectly, or is this an issue in XcodeKit or Xcode?