Skip to content

Commit

Permalink
better argument validation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
MahdiBM committed Jul 19, 2024
1 parent 89b24ff commit bb8b234
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Sources/EnumeratorMacroImpl/Arguments.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct Arguments {
throw MacroError.unacceptableArguments
}
if exprList.isEmpty {
throw MacroError.expectedAtLeastOneArgument
throw MacroError.expectedAtLeastOneValidArgument
}
for element in exprList {
switch element.expression.kind {
Expand Down
2 changes: 2 additions & 0 deletions Sources/EnumeratorMacroImpl/EnumeratorMacroType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ extension EnumeratorMacroType: MemberMacro {
arguments: arguments,
context: context
)

/// Validate comments
if let allowedComments = parsedArguments.allowedComments,
!allowedComments.keys.isEmpty {

Expand Down
10 changes: 5 additions & 5 deletions Sources/EnumeratorMacroImpl/MacroError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ enum MacroError: Error, CustomStringConvertible {
case isNotEnum
case macroDeclarationHasNoArguments
case unacceptableArguments
case expectedAtLeastOneArgument
case expectedAtLeastOneValidArgument
case invalidArgument
case expectedNonInterpolatedStringLiteral
case renderedSyntaxContainsErrors(String)
Expand All @@ -24,8 +24,8 @@ enum MacroError: Error, CustomStringConvertible {
"macroDeclarationHasNoArguments"
case .unacceptableArguments:
"unacceptableArguments"
case .expectedAtLeastOneArgument:
"expectedAtLeastOneArgument"
case .expectedAtLeastOneValidArgument:
"expectedAtLeastOneValidArgument"
case .invalidArgument:
"invalidArgument"
case .expectedNonInterpolatedStringLiteral:
Expand Down Expand Up @@ -55,8 +55,8 @@ enum MacroError: Error, CustomStringConvertible {
"The macro declaration needs to have at least 1 String-Literal argument"
case .unacceptableArguments:
"The arguments passed to the macro were unacceptable"
case .expectedAtLeastOneArgument:
"At least one argument of type StaticString is required"
case .expectedAtLeastOneValidArgument:
"At least one valid argument is required"
case .invalidArgument:
"Invalid argument received"
case .expectedNonInterpolatedStringLiteral:
Expand Down

0 comments on commit bb8b234

Please sign in to comment.