Skip to content

Commit

Permalink
feat: add debug log in event of failure
Browse files Browse the repository at this point in the history
  • Loading branch information
elihwyma committed Nov 24, 2024
1 parent 540e1c9 commit fd56f40
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions Sources/PugiSwiftMacros/NodeMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,22 @@ public struct NodeMacro: ExtensionMacro {

if optional {
if attribute {
#if DEBUG
let code = CodeBlockItemSyntax(
"""
if let \(raw: nodeHelperName) = node.attribute(name: "\(raw: codingKey)") {
do {
self.\(raw: propertyName) = try .init(from: \(raw: nodeHelperName))
} catch {
self.\(raw: propertyName) = nil
print("[🐞] Parsing error in \(raw: propertyName): \\(error.localizedDescription)")
}
} else {
self.\(raw: propertyName) = nil
}
"""
)
#else
let code = CodeBlockItemSyntax(
"""
if let \(raw: nodeHelperName) = node.attribute(name: "\(raw: codingKey)") {
Expand All @@ -107,6 +123,7 @@ public struct NodeMacro: ExtensionMacro {
}
"""
)
#endif
return [code]
} else {
if let childrenCodingKey {
Expand Down Expand Up @@ -134,6 +151,22 @@ public struct NodeMacro: ExtensionMacro {
)
return [code]
} else {
#if DEBUG
let code = CodeBlockItemSyntax(
"""
if let \(raw: nodeHelperName) = node.child(name: "\(raw: codingKey)") {
do {
self.\(raw: propertyName) = try .init(from: \(raw: nodeHelperName))
} catch {
self.\(raw: propertyName) = nil
print("[🐞] Parsing error in \(raw: propertyName): \\(error.localizedDescription)")
}
} else {
self.\(raw: propertyName) = nil
}
"""
)
#else
let code = CodeBlockItemSyntax(
"""
if let \(raw: nodeHelperName) = node.child(name: "\(raw: codingKey)") {
Expand All @@ -143,6 +176,7 @@ public struct NodeMacro: ExtensionMacro {
}
"""
)
#endif
return [code]
}
}
Expand Down

0 comments on commit fd56f40

Please sign in to comment.