-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
fs.cwd().openDir().iterate() panics if called without OpenDirOptions.iterate = true
on Linux (Ubuntu), works fine on MacOS
#12007
Comments
Currently, Anyway, I was surprised the call seems to work on MacOS anyway, but panics on Ubuntu... I can check Windows too if needed. |
This is expected behaviour, is intended, and is documented. |
This is not documented in either openDir() or iterate(). Please show me where this is mentioned. Also, is this a good idea you think? |
Is this what you say documents this behaviour? pub const OpenDirOptions = struct {
...
/// `true` means the opened directory can be scanned for the files and sub-directories
/// of the result. It means the `iterate` function can be called.
iterate: bool = false, I really disagree if so. Panics shouldn't be treated so lightly like that. Are we trying to write a language that is robust or what? |
OpenDirOptions.iterate = true
on Linux (Ubuntu)OpenDirOptions.iterate = true
on Linux (Ubuntu), works fine on MacOS
It is stated here. Lines 1486 to 1488 in 93ac87c
Yes, the status quo is correct. I don't know why you're reacting with a 👎 to me stating the facts lol.
You wrote incorrect code; I don't know what you expect Zig to do for you here... |
The language panics because you wrote wrong code, I think is fair... Please calm down on the panics, they are expected side of the language, the panics should probably guide more, and I think is better than a silent error. |
You could perhaps propose (or make a pull request) to add an explicit comment to |
@renatoathaydes Thanks for opening this issue! You are right that there's an inconsistency here that should be fixed.
|
Same here -- this would require adding a check with a runtime overhead.
I'll get to doing this if nobody else does before me. |
I am. I think this error is common enough that it warrants a runtime check in debug modes. |
I don't see this error so often, and the obvious comment in the error trace which points people who read it to where they need to go seems to be sufficient to me. I'd prefer a comptime check if anything, but that's clearly not possible/feasible. Though I'm sure I'm missing something here, so will leave you to it lol. It was suggested by @kubkon in Discord that not enough newbies understand that a common pattern in Zig is that incorrect code will cause panics or reach unreachable statements. Perhaps it is as or more important that this is better portrayed in Zig docs. |
@ominitay It's not sufficient to me. By a large margin. Clearly, if it's sufficient to you, we have very different criteria to decide when documentation is sufficient to warn against a panic.
Because you treat someone who takes the time to report an error and try the code in different operating systems with disdain as if we are idiots, and you know it all and have the power to decide when there's enough documentation, and others shouldn't have an opinion that contradicts yours otherwise you just "lol". @SpexGuy thanks for the welcoming treatment. That's what I would expect from a community where people want to help each other instead of demanding full understanding of every option when calling a function. Don't you think that |
maybe in some cases like a file browser, but generally speaking, not by a long shot. typically you know the exact pattern of file names you're going to access, which is not inhibited by |
I agree with you on this. That you didn't know about this behaviour demonstrates that the documentation isn't clear enough about this behaviour.
This will panic, that is the intended behaviour (as it is a programming mistake, not a runtime failure), and will not change. (Debug mode) panics are sufficient here, as the compiler can optimise better in release mode, and they allow devs to debug their code in debug mode.
Please refrain from using personal attacks and making accusations against others. It doesn't help us get anywhere, and serves only to derail the discussion. I didn't treat you as or think of you as an idiot. I also didn't say that there is enough documentation. You can see that for yourself in this post and my previous one above :)
No, I don't want any negativity between us, sorry if my message came across in a different tone than I intended. |
Just to throw this out there, another solution would be to make a separate type " This would document, in code, at the type level, that there is a decision to be made about the explicitly desired capabilities of a directory handle. Though, personally, I think a debug-only runtime check would be sufficient. More front-and-center documentation would be even better; perhaps on any relevant functions, as I'm not sure how many people really go out of their way to read the field comments of struct parameters. |
This sounds interesting, although I question the practicality of it, in comparison with a simple debug runtime check (which I now feel I agree with having).
Better documentation is really important here. This reminds me kind of about HashMap, where a function didn't directly mention that it invalidated references, even though it was documented. |
Speaking on behalf of @ominitay, just wanted to mention that after discussing it over discord, they've come to the conclusion that |
That makes sense. An API that takes an options object but returns the same type regardless of the options, but which only allows some of the operations on the returned type to be used is simply under-using the power of types... in other words, it's leaning in the direction of dynamic typing almost... so having a more specific function that returns a more specific type that describes precisely the operations that can be performed is absolutely better. |
Zig Version
0.10.0-dev.2577+5816d3eae
Steps to Reproduce
Call this:
Expected Behavior
The call should return an error as the default is iterate=false.
On MacOS, no error happens at all, which is probably also a bug?
Actual Behavior
The text was updated successfully, but these errors were encountered: