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

Improve FileSystemError by adding associated path #167

Merged
merged 1 commit into from
Nov 16, 2020
Merged

Conversation

MaxDesiatov
Copy link
Contributor

Another attempt to apply #78, which was previously reverted due to breakage in SourceKit-LSP.

I've recently stumbled upon this error when running swift build:

error: noEntry

This is the exact and only output of this swift build invocation. Unfortunately, I think it's impossible to diagnose without an attached debugger. It's also hard to pinpoint where exactly the error comes from in the source code, since FileSystemError.noEntry is thrown from multiple places.

In my opinion, for an error value to be helpful it should have associated information attached to it. In this case, it would make sense for almost all cases of FileSystemError to have an associated AbsolutePath value.

FileSystemError now also has to be explicitly declared Equatable to make the tests compile, but previously it was Equatable anyway, although implicitly by virtue of being an enum with no associated values.

I've recently stumbled upon this error when running `swift build`:

```
error: noEntry
```

This is the exact and only output of this `swift build` invocation. Unfortunately, I think it's impossible to diagnose without an attached debugger. It's also hard to pinpoint where exactly the error comes from in the source code, since `FileSystemError.noEntry` is thrown from multiple places.

In my opinion, for an error value to be helpful it should have associated information attached to it. In this case, it would make sense for almost all cases of `FileSystemError` to have an associated `AbsolutePath` value.

`FileSystemError` now also has to be explicitly declared `Equatable` to make the tests compile, but previously it was `Equatable` anyway, although implicitly by virtue of being an enum with no associated values.
@MaxDesiatov
Copy link
Contributor Author

@swift-ci please test

Copy link
Contributor

@abertelrud abertelrud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! The changes in this PR so far look good to me. It's unfortunate to have to switch to a struct, but adding a path to each enum case would be even more cumbersome, I think. There might also be cases in which a client might want to access the path without having to check each specific code, so this makes sense.

/// path already contains a file or folder.
case alreadyExistsAtDestination
public struct FileSystemError: Swift.Error, Equatable {
public enum Kind: Equatable {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's unfortunate to have to split this into a kind and a path, I think, but adding a path to every enum case would be even more unfortunate.

/// to.
///
/// Used in situations that correspond to the POSIX ENOENT error code.
case noEntry
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to record any information here about whether symlink traversal was in effect when the error occurred, e.g. if I'm accessing path where a symlink is the last path component, I would get this error if a symlink was being resolved but not get it if it wasn't. This is known at the callsite but cannot be inferred from the error. I suppose that is actually something that could apply to any of the errors here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would you prefer to record that? A separate property on this new struct?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, actually — at first I was thinking a boolean on each of the enum cases where it made sense, but perhaps it would belong as a separate boolean next to the path. But this could easily be added later in a separate PR, I think.

@MaxDesiatov MaxDesiatov merged commit d59c9e0 into main Nov 16, 2020
@MaxDesiatov MaxDesiatov deleted the maxd/fserror branch November 16, 2020 20:21
@compnerd
Copy link
Member

This seems to have broken the Windows build :-( Can we revert this?

@MaxDesiatov
Copy link
Contributor Author

MaxDesiatov commented Nov 17, 2020

How hard would it be to have a look at a build log with the error message? I'm happy to create a separate PR with a fix for Windows if that would be acceptable instead of the revert?

@compnerd
Copy link
Member

@MaxDesiatov if it can be merged immediately, sure I suppose that might work, but changes like this should really be tested before merging - changes to the file system codepaths are very sensitive since the file system implementation in TSC really needs to abstract over the underlying system and does not do so.

@MaxDesiatov
Copy link
Contributor Author

I'd love to be able to test it, is there any plan to set up Windows CI for SwiftPM?

@compnerd
Copy link
Member

compnerd commented Nov 17, 2020

@tomerd was going to look into that I believe - there is already a periodic CI: https://dev.azure.com/compnerd/swift-build/_build?definitionId=57
You should be able to build it locally in a VM though.

compnerd added a commit to compnerd/swift-tools-support-core that referenced this pull request Nov 17, 2020
@MaxDesiatov
Copy link
Contributor Author

MaxDesiatov commented Nov 17, 2020

Thanks! The other complication is that this is a cross-repo PR that needs to be reverted here, in SwiftPM, and SourceKit-LSP. I'll submit revert PRs in appropriate repos then...

@MaxDesiatov
Copy link
Contributor Author

there is already a periodic CI: https://dev.azure.com/compnerd/swift-build/_build?definitionId=57

@compnerd I tried to have a look, but constnantly getting this error: TF400813: The user 'Windows Live ID\\[email protected]' is not authorized to access this resource

@compnerd
Copy link
Member

Interesting, that is new, Ill take a look at the settings - its supposed to be visible to everyone; in any case put up #169

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants