Skip to content

Commit b354d67

Browse files
committed
Print the correct command as an error prefix
1 parent 1581726 commit b354d67

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

Sources/Multitool/Error.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ extension Error: CustomStringConvertible {
3636
@noreturn public func handleError(msg: Any, usage: ((String) -> Void) -> Void) {
3737
switch msg {
3838
case CommandLineError.InvalidUsage(let hint, let mode):
39-
perror("invalid usage: \(hint)")
39+
print(error: "invalid usage: \(hint)")
4040

4141
if isatty(fileno(libc.stdin)) {
4242
switch mode {
@@ -50,7 +50,7 @@ extension Error: CustomStringConvertible {
5050
}
5151
}
5252
default:
53-
perror(msg)
53+
print(error: msg)
5454
}
5555

5656
exit(1)
@@ -63,10 +63,11 @@ private func red(input: Any) -> String {
6363
return CSI + "31m" + input + CSI + "0m"
6464
}
6565

66-
private func perror(msg: Any) {
66+
private func print(error error: Any) {
6767
if !isatty(fileno(libc.stderr)) {
68-
print("swift-build: error:", msg, to: &stderr)
68+
let cmd = Process.arguments.first?.basename ?? "SwiftPM"
69+
print("\(cmd): error:", error, to: &stderr)
6970
} else {
70-
print(red("error:"), msg, to: &stderr)
71+
print(red("error:"), error, to: &stderr)
7172
}
7273
}

0 commit comments

Comments
 (0)