-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
compiler: Introduce non-nilable read_file macro #7094
Conversation
The original (nilable) macro has been renamed to `read_file?`.
Prior was with a bare raise in the compiler.
@last = StringLiteral.new(File.read(filename)) | ||
else | ||
rescue e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e
-> ex
plz
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, one question is if it is a good idea to rescue all possible errors instead of only the specific one that is raised if the file doesn't exist.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yxhuvud I don't see a problem with it since they're re-raised and the only meaningful call (which might raise) is File.read
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and the only meaningful call (which might raise) is
File.read
Yep, this was my reasoning here 🙂
I vote close this PR. the |
Two counterexamples: Both the Similarly, from the end user's perspective, I'd argue that raising an error is a better default: returning a |
@RX14 the If I embed a file, I expect the file to exist and be readable. I want a compile time error with the actual reason if it failed to. I don't want to deal with a nilable or have to raise myself a redundant |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I thought system
didn't raise. I guess this is fine then.
Follow-up on #6967.
The original (nilable) macro has been renamed to
read_file?
.