-
-
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
Windows PartitionsWithContext is over cautious with error handling. #572
Comments
So basically we should not return ASAP at Line 116 in 8563278
I see different options:
To sum up:
I'm leaning towards the custom error type. |
Option 3 would not break downstream code but it would also not fix them either. If callers do the naive My preference is that the PartitionStat struct be extended to contain the error for each partition if the callers cared to inspect it, otherwise just leave the fstype and options fields empty. |
Perhaps I don't get what the actual problem is, but from my understanding the issue is, only an error will be returned if invalid partition exists. First of all, Second of all, if there are several partitions and only one partition has error, This means, like this.
What do you think? |
This works for me. The main thing is that it continues the loop and finishes enumerating all the drives. It perfectly fine to omit the drives which have errors but at least we can get the other drives. The use pattern will be a little more complicated than just check for err != nil but that's ok. One will have to check for len of result > 0 means there are valid results even if err != nil, if the caller cares about other partitions then they would look in err more closely. The more idiomatic approach is to make a new Error type with a list of errors in it, then users can check for it specifically. It will not break existing code since users will need to type assert it to access the new functionality (existing code will just see an error and do what it already does - but of course it will still be broken because it will probably raise the error up the stack.):
Then users can just check for it if they cared:
Either of the two options are ok moving forward but they do not fix existing usage. As you say " Error handling is caller responsibility. So we don't care about if some programs break without certain error handling." but this is the whole point - existing callers are handling the errors and because of this handling they reject correct results and receive an unexpected bug (i.e. they get total failure and no results in cases where there is only a partial failure). You are effectively changing the contract of the function moving forward. |
Not that much I think. Previous code using Not returning the error encountered while retrieving fs properties is breaking back-compatibility in a harder way than this new custom error type. Between minor releases we have to keep the same behavior and API. Adding the Err field in PartitionStat adds another way to check errors while we already have the error returned by the function. I can find some implementations using custom error types to wrap a list of errors (even in the stdlib), it looks like the consensus in this reddit thread and feels more idiomatic to me. Of course the documentation will have to be updated to show how to properly check this error and how to know which PartitionStat failed.
This can be the case with the current code, if we fail at the mentioned line 116 we don't return empty results but what was found until this error occurred. |
Windows PartitionsWithContext exits the function in several places where the win32 API can return errors for certain operations. But exiting the entire function means that no partition information is returned at all. This is problematic because programs that rely on this function suddenly and unexpectedly break when inaccessible volumes are attached.
For example attaching a locked bitlocker volume to the system will cause any program to return 0 drives and an error. This happens because provGetVolumeInformation.Call() returns an error on this volume something like "This drive is locked by BitLocker".
This function should return all the information it has on all drives - even if it cant get some information due to the error. Let the caller deal with handling certain errors.
The text was updated successfully, but these errors were encountered: