feat: Return ErrNotExist when a distro does not exist #106
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I read somewhere (I think some python style guide) that there are two patterns to access resources:
The first is inherently racy as the availability of the resource may change after asking for permission. This lead our implementation to become an ask for permission, then ask for forgiveness sandwich which is needlesly verbose:
This PR makes usage a bit safer and less redundant:
Note that internally we do ask for permission in some places, essentially every Win32 API call. This is because the error reporting of these DLL calls is atrocious, and we cannot produce a meaningful error message from them.
This is not for sport. The current implementation caused a test failure due to a resource availability race:
Failure: https://github.com/canonical/ubuntu-pro-for-wsl/actions/runs/8062559006/job/22022548242?pr=606#step:8:29
Code: https://github.com/canonical/ubuntu-pro-for-wsl/blob/f31559d796e8f2421acfbf4056e86e8f06854171/windows-agent/internal/distros/distro/properties.go#L34-L46
Part of UDENG-2385