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

I want a parameter in TextFile that will cause a compile error if the file specified in Path does not exist. #14

Closed
wraikny opened this issue Aug 20, 2021 · 4 comments
Labels
enhancement New feature or request

Comments

@wraikny
Copy link

wraikny commented Aug 20, 2021

In the current implementation of TextFile, DefaultValue is used for the Text member if the file specified in Path does not exist. If DefaultValue is not specified, it will be an empty string.

If the contents of the file should always be used, but a non-existent file path is specified (for example, due to a mistake in the file path, a change in the file name, or a difference in the build environment), empty string is used as DefaultValue and no error occurs. This can cause unexpected bugs.

I think there is a way, for example, to add a bool type parameter named UseDefaultValue and raise an exception if the file is not found and this parameter is false.

@Tarmil
Copy link
Owner

Tarmil commented Aug 20, 2021

One way to ensure the existence of the file is to use the non-parameterized version of the provider, ie instead of TextFile<"foo/bar.txt">, use TextFile.foo.``bar.txt``.

But now I realize that you might want to provide the path as a string anyway (perhaps because it itself comes from another LiteralProvider), so yeah then this makes sense.

@Tarmil Tarmil added the enhancement New feature or request label Aug 20, 2021
@wraikny
Copy link
Author

wraikny commented Aug 21, 2021

In my situation I had to specify the file path of the project's parent hierarchy (for example, ../../misc/foobar.txt). In any case, thank you for your consideration.

@Tarmil
Copy link
Owner

Tarmil commented Aug 25, 2021

There's actually another improvement that could be done, and would also solve your issue: making the non-parameterized version also provide a ``..`` to access the parent folder. But it gets pretty hard to read:

Textfile.``..``.``..``.misc.``foobar.txt``

@Tarmil
Copy link
Owner

Tarmil commented May 22, 2022

Released in v0.4 as EnsureExists.

@Tarmil Tarmil closed this as completed May 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants