Skip to content

Commit 353c863

Browse files
authored
Fix close error message (#433)
From the macOS manpage: > Upon successful completion, a value of 0 is returned. Otherwise, a value > of -1 is returned and the global integer variable errno is set to > indicate the error. I'm not certain whether the existing code may be there for cross-platform support, so I changed it to check for -1 and only then consult the global `errno`. This should preserve existing behavior if there's a cross-platform angle here. rdar://117861543
1 parent 13dc95b commit 353c863

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Sources/TSCBasic/misc.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,14 @@ extension SystemError: CustomStringConvertible {
347347
switch self {
348348
case .chdir(let errno, let path):
349349
return "chdir error: \(strerror(errno)): \(path)"
350-
case .close(let errno):
351-
return "close error: \(strerror(errno))"
350+
case .close(let err):
351+
let errorMessage: String
352+
if err == -1 { // if the return code is -1, we need to consult the global `errno`
353+
errorMessage = strerror(errno)
354+
} else {
355+
errorMessage = strerror(err)
356+
}
357+
return "close error: \(errorMessage)"
352358
case .exec(let errno, let path, let args):
353359
let joinedArgs = args.joined(separator: " ")
354360
return "exec error: \(strerror(errno)): \(path) \(joinedArgs)"

0 commit comments

Comments
 (0)