@@ -146,14 +146,29 @@ struct ParsableArgumentsCodingKeyValidator: ParsableArgumentsValidator {
146146
147147 /// This error indicates that an option, a flag, or an argument of
148148 /// a `ParsableArguments` is defined without a corresponding `CodingKey`.
149- struct Error : ParsableArgumentsValidatorError , CustomStringConvertible {
149+ struct MissingKeysError : ParsableArgumentsValidatorError , CustomStringConvertible {
150150 let missingCodingKeys : [ String ]
151151
152152 var description : String {
153+ let resolution = """
154+ To resolve this error, make sure that all properties have corresponding
155+ cases in your custom `CodingKey` enumeration.
156+ """
157+
153158 if missingCodingKeys. count > 1 {
154- return " Arguments \( missingCodingKeys. map ( { " ` \( $0) ` " } ) . joined ( separator: " , " ) ) are defined without corresponding `CodingKey`s. "
159+ return """
160+ Arguments \( missingCodingKeys. map ( { " ` \( $0) ` " } ) . joined ( separator: " , " ) ) \
161+ are defined without corresponding `CodingKey`s.
162+
163+ \( resolution)
164+ """
155165 } else {
156- return " Argument ` \( missingCodingKeys [ 0 ] ) ` is defined without a corresponding `CodingKey`. "
166+ return """
167+ Argument ` \( missingCodingKeys [ 0 ] ) ` is defined without a corresponding \
168+ `CodingKey`.
169+
170+ \( resolution)
171+ """
157172 }
158173 }
159174
@@ -162,6 +177,23 @@ struct ParsableArgumentsCodingKeyValidator: ParsableArgumentsValidator {
162177 }
163178 }
164179
180+ struct InvalidDecoderError : ParsableArgumentsValidatorError , CustomStringConvertible {
181+ let type : ParsableArguments . Type
182+
183+ var description : String {
184+ """
185+ The implementation of `init(from:)` for ` \( type) `
186+ is not compatible with ArgumentParser. To resolve this issue, make sure
187+ that `init(from:)` calls the `container(keyedBy:)` method on the given
188+ decoder and decodes each of its properties using the returned decoder.
189+ """
190+ }
191+
192+ var kind : ValidatorErrorKind {
193+ . failure
194+ }
195+ }
196+
165197 static func validate( _ type: ParsableArguments . Type ) -> ParsableArgumentsValidatorError ? {
166198 let argumentKeys : [ String ] = Mirror ( reflecting: type. init ( ) )
167199 . children
@@ -179,11 +211,11 @@ struct ParsableArgumentsCodingKeyValidator: ParsableArgumentsValidator {
179211 }
180212 do {
181213 let _ = try type. init ( from: Validator ( argumentKeys: argumentKeys) )
182- fatalError ( " The validator should always throw. " )
214+ return InvalidDecoderError ( type : type )
183215 } catch let result as Validator . ValidationResult {
184216 switch result {
185217 case . missingCodingKeys( let keys) :
186- return Error ( missingCodingKeys: keys)
218+ return MissingKeysError ( missingCodingKeys: keys)
187219 case . success:
188220 return nil
189221 }
@@ -244,9 +276,11 @@ struct NonsenseFlagsValidator: ParsableArgumentsValidator {
244276 """
245277 One or more Boolean flags is declared with an initial value of `true`.
246278 This results in the flag always being `true`, no matter whether the user
247- specifies the flag or not. To resolve this error, change the default to
248- `false`, provide a value for the `inversion:` parameter, or remove the
249- `@Flag` property wrapper altogether.
279+ specifies the flag or not.
280+
281+ To resolve this error, change the default to `false`, provide a value
282+ for the `inversion:` parameter, or remove the `@Flag` property wrapper
283+ altogether.
250284
251285 Affected flag(s):
252286 \( names. joined ( separator: " \n " ) )
0 commit comments