Skip to content

Commit 6a37d80

Browse files
committed
modify error message
1 parent 2b2fb73 commit 6a37d80

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

Diff for: Sources/Macros/Expression/LoggingExpressionMacros.swift

+14-6
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
import SwiftDiagnostics
22
import SwiftSyntax
3+
import SwiftSyntaxMacroExpansion
34
import SwiftSyntaxMacros
45

56
/// OS 버전에 따라 Logger의 호출이 달라지므로, 조건에 따라 변경이 필요함
67
public struct LoggingExpressionMacros: ExpressionMacro {
78
public static func expansion(
89
of node: some FreestandingMacroExpansionSyntax,
910
in context: some MacroExpansionContext
10-
) -> ExprSyntax {
11+
) throws -> ExprSyntax {
1112
let argumentList = node.argumentList
1213
guard
1314
argumentList.count == 2,
1415
let firstElement = argumentList.first,
1516
let secondElement = argumentList.last
1617
else {
17-
fatalError("compiler bug: the macro does not have any arguments")
18+
throw MacroExpansionErrorMessage(
19+
"log는 OSLogType, message이 필요합니다. 확인해주세요"
20+
)
1821
}
1922

2023
let oslogType = firstElement.expression
@@ -26,10 +29,15 @@ public struct LoggingExpressionMacros: ExpressionMacro {
2629
.as(StringSegmentSyntax.self)?
2730
.content.text
2831

29-
guard
30-
let oslogType, let msg
31-
else {
32-
fatalError("compiler bug: the macro does not have any arguments")
32+
guard let oslogType else {
33+
throw MacroExpansionErrorMessage(
34+
"log는 OSLogType, message이 필요합니다. 확인해주세요"
35+
)
36+
}
37+
guard let msg else {
38+
throw MacroExpansionErrorMessage(
39+
"message 타입이 String인지 확인해주세요"
40+
)
3341
}
3442

3543
return "\(raw: generateExpr(oslogType: oslogType, msg: msg))"

0 commit comments

Comments
 (0)