Open MahdiBM opened 1 month ago
I could make the render function throwing. Seems odd to add a task local to store errors. Although these could be considered warnings I guess. The other thing that could cause a warning is missed variables ie {{var}}
when var
doesn't exist.
Yeah using task locals is odd, but I guess that was the best I could come up with without manipulating swift-mustache, in EnumeratorMacro.
EnumeratorMacro is now using pretty much only internal wrapper types so it can have full control over transforms etc... so this is no longer an issue for me, because I won't be falling back to swift-mustache's transforms.
But it is still a question if swift-mustache should report errors better anyways and not be loose like in JS. Possibly having an option to configure.
I just implemented this for EnumeratorMacro:
This will basically report back if a function call is invalid, and won't result in a silent failure. Note that this is only possible because
EnumeratorMacro
defines its own wrapper types to have control over the transforms.How it works is using a
TaskLocal
: https://github.com/MahdiBM/enumerator-macro/blob/0a1b67d2941dec346f59f06d0c7c86888712aae0/Sources/EnumeratorMacroImpl/EnumeratorMacroType.swift#L50 Which are used to store an error: https://github.com/MahdiBM/enumerator-macro/blob/0a1b67d2941dec346f59f06d0c7c86888712aae0/Sources/EnumeratorMacroImpl/Types/EString.swift#L70I think swift-mustache can also have such an option. If the user has inserted a value for the TaskLocal, swift-mustache will populate it. swift-mustache seems a
nil
task-local value and just moves on with the current behavior. The TaskLocal should be defined in swift-mustache, but it just defaults tonil
which would result in no capturing of errors.