1
1
import SwiftDiagnostics
2
2
import SwiftSyntax
3
+ import SwiftSyntaxMacroExpansion
3
4
import SwiftSyntaxMacros
4
5
5
6
/// OS 버전에 따라 Logger의 호출이 달라지므로, 조건에 따라 변경이 필요함
6
7
public struct LoggingExpressionMacros : ExpressionMacro {
7
8
public static func expansion(
8
9
of node: some FreestandingMacroExpansionSyntax ,
9
10
in context: some MacroExpansionContext
10
- ) -> ExprSyntax {
11
+ ) throws -> ExprSyntax {
11
12
let argumentList = node. argumentList
12
13
guard
13
14
argumentList. count == 2 ,
14
15
let firstElement = argumentList. first,
15
16
let secondElement = argumentList. last
16
17
else {
17
- fatalError ( " compiler bug: the macro does not have any arguments " )
18
+ throw MacroExpansionErrorMessage (
19
+ " log는 OSLogType, message이 필요합니다. 확인해주세요 "
20
+ )
18
21
}
19
22
20
23
let oslogType = firstElement. expression
@@ -26,10 +29,15 @@ public struct LoggingExpressionMacros: ExpressionMacro {
26
29
. as ( StringSegmentSyntax . self) ?
27
30
. content. text
28
31
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
+ )
33
41
}
34
42
35
43
return " \( raw: generateExpr ( oslogType: oslogType, msg: msg) ) "
0 commit comments