in Sources/ArgumentParser/Usage/UsageGenerator.swift [396:425]
func unableToParseValueMessage(origin: InputOrigin, name: Name?, value: String, key: InputKey, error: Error?) -> String {
let argumentValue = arguments(for: key).first
let valueName = argumentValue?.valueName
// We want to make the "best effort" in producing a custom error message.
// We favor `LocalizedError.errorDescription` and fall back to
// `CustomStringConvertible`. To opt in, return your custom error message
// as the `description` property of `CustomStringConvertible`.
let customErrorMessage: String = {
switch error {
case let err as LocalizedError where err.errorDescription != nil:
return ": " + err.errorDescription! // !!! Checked above that this will not be nil
case let err?:
return ": " + String(describing: err)
default:
return argumentValue?.formattedValueList ?? ""
}
}()
switch (name, valueName) {
case let (n?, v?):
return "The value '\(value)' is invalid for '\(n.synopsisString) <\(v)>'\(customErrorMessage)"
case let (_, v?):
return "The value '\(value)' is invalid for '<\(v)>'\(customErrorMessage)"
case let (n?, _):
return "The value '\(value)' is invalid for '\(n.synopsisString)'\(customErrorMessage)"
case (nil, nil):
return "The value '\(value)' is invalid.\(customErrorMessage)"
}
}