Skip to content

Reduce the use unknownError in FileSystem #276

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

Merged
merged 1 commit into from
Jan 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions Sources/TSCBasic/FileSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ public struct FileSystemError: Error, Equatable {
/// This is thrown when copying or moving a file or directory but the destination
/// path already contains a file or folder.
case alreadyExistsAtDestination

/// If an unspecified error occurs when trying to change directories.
case couldNotChangeDirectory

/// If a mismatch is detected in byte count when writing to a file.
case mismatchedByteCount(expected: Int, actual: Int)
}

/// The kind of the error being raised.
Expand Down Expand Up @@ -99,7 +105,7 @@ public extension FileSystemError {
case TSCLibc.ENOTDIR:
self.init(.notDirectory, path)
default:
self.init(.unknownOSError, path)
self.init(.ioError(code: errno), path)
}
}
}
Expand Down Expand Up @@ -343,7 +349,7 @@ private class LocalFileSystem: FileSystem {
}

guard FileManager.default.changeCurrentDirectoryPath(path.pathString) else {
throw FileSystemError(.unknownOSError, path)
throw FileSystemError(.couldNotChangeDirectory, path)
}
}

Expand Down Expand Up @@ -440,7 +446,7 @@ private class LocalFileSystem: FileSystem {
throw FileSystemError(.ioError(code: errno), path)
}
if n != contents.count {
throw FileSystemError(.unknownOSError, path)
throw FileSystemError(.mismatchedByteCount(expected: contents.count, actual: n), path)
}
break
}
Expand Down