Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A way to have a report of error situations #40

Open
MahdiBM opened this issue Jul 16, 2024 · 2 comments
Open

A way to have a report of error situations #40

MahdiBM opened this issue Jul 16, 2024 · 2 comments

Comments

@MahdiBM
Copy link
Contributor

MahdiBM commented Jul 16, 2024

I just implemented this for EnumeratorMacro:

Screenshot 2024-07-16 at 10 46 36 PM

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#L70

I 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 to nil which would result in no capturing of errors.

@MahdiBM MahdiBM changed the title A way to report of "error" situations A way to have a report of error situations Jul 16, 2024
@adam-fowler
Copy link
Member

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.

@MahdiBM
Copy link
Contributor Author

MahdiBM commented Jul 18, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants