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

Fix use of errno in SystemError #455

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Sources/TSCBasic/Process/Process.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1362,7 +1362,7 @@ private func close(fd: Int32) throws {
func innerClose(_ fd: inout Int32) throws {
let rv = TSCLibc.close(fd)
guard rv == 0 else {
throw SystemError.close(rv)
throw SystemError.close(errno)
}
}
var innerFd = fd
Expand Down
10 changes: 2 additions & 8 deletions Sources/TSCBasic/misc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -347,14 +347,8 @@ extension SystemError: CustomStringConvertible {
switch self {
case .chdir(let errno, let path):
return "chdir error: \(strerror(errno)): \(path)"
case .close(let err):
let errorMessage: String
if err == -1 { // if the return code is -1, we need to consult the global `errno`
errorMessage = strerror(errno)
} else {
errorMessage = strerror(err)
}
return "close error: \(errorMessage)"
case .close(let errno):
return "close error: \(strerror(errno))"
case .exec(let errno, let path, let args):
let joinedArgs = args.joined(separator: " ")
return "exec error: \(strerror(errno)): \(path) \(joinedArgs)"
Expand Down
2 changes: 1 addition & 1 deletion Sources/TSCUtility/InterruptHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public final class InterruptHandler {
// Create pipe.
let rv = TSCLibc.pipe(&Self.signalWatchingPipe)
guard rv == 0 else {
throw SystemError.pipe(rv)
throw SystemError.pipe(errno)
}
#endif

Expand Down