Skip to content

Commit 3cfb7e2

Browse files
authored
Merge pull request #276 from neonichu/reduce-unknown-errors
Reduce the use `unknownError` in `FileSystem`
2 parents bc0d6a7 + 446922b commit 3cfb7e2

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

Sources/TSCBasic/FileSystem.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ public struct FileSystemError: Error, Equatable {
6767
/// This is thrown when copying or moving a file or directory but the destination
6868
/// path already contains a file or folder.
6969
case alreadyExistsAtDestination
70+
71+
/// If an unspecified error occurs when trying to change directories.
72+
case couldNotChangeDirectory
73+
74+
/// If a mismatch is detected in byte count when writing to a file.
75+
case mismatchedByteCount(expected: Int, actual: Int)
7076
}
7177

7278
/// The kind of the error being raised.
@@ -99,7 +105,7 @@ public extension FileSystemError {
99105
case TSCLibc.ENOTDIR:
100106
self.init(.notDirectory, path)
101107
default:
102-
self.init(.unknownOSError, path)
108+
self.init(.ioError(code: errno), path)
103109
}
104110
}
105111
}
@@ -343,7 +349,7 @@ private class LocalFileSystem: FileSystem {
343349
}
344350

345351
guard FileManager.default.changeCurrentDirectoryPath(path.pathString) else {
346-
throw FileSystemError(.unknownOSError, path)
352+
throw FileSystemError(.couldNotChangeDirectory, path)
347353
}
348354
}
349355

@@ -440,7 +446,7 @@ private class LocalFileSystem: FileSystem {
440446
throw FileSystemError(.ioError(code: errno), path)
441447
}
442448
if n != contents.count {
443-
throw FileSystemError(.unknownOSError, path)
449+
throw FileSystemError(.mismatchedByteCount(expected: contents.count, actual: n), path)
444450
}
445451
break
446452
}

0 commit comments

Comments
 (0)