Skip to content

Commit 11217e2

Browse files
committed
Swift Driver: Unknown Subcommand Location
Include the path that the Swift driver is looking for a subcommand in the error message. This makes it easier to see where the driver is looking, which isn't always next to the driver.
1 parent 0e6d6dd commit 11217e2

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ extension Driver.ErrorDiagnostics: CustomStringConvertible {
5151
/// The Swift driver.
5252
public struct Driver {
5353
public enum Error: Swift.Error, Equatable, DiagnosticData {
54-
case unknownOrMissingSubcommand(String)
54+
case unknownOrMissingSubcommand(String, String?)
5555
case invalidDriverName(String)
5656
case invalidInput(String)
5757
case noInputFiles
@@ -82,7 +82,10 @@ public struct Driver {
8282

8383
public var description: String {
8484
switch self {
85-
case .unknownOrMissingSubcommand(let subcommand):
85+
case .unknownOrMissingSubcommand(let subcommand, let directory):
86+
if let directory {
87+
return "unknown or missing subcommand '\(subcommand)' in '\(directory)'"
88+
}
8689
return "unknown or missing subcommand '\(subcommand)'"
8790
case .invalidDriverName(let driverName):
8891
return "invalid driver name: \(driverName)"

Sources/swift-driver/main.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,11 @@ do {
108108
let legacyDriverCommand = [path] + CommandLine.arguments[1...]
109109
try exec(path: path, args: legacyDriverCommand)
110110
} else {
111-
throw Driver.Error.unknownOrMissingSubcommand(legacyExecutablePath.lastPathComponent)
111+
throw Driver.Error.unknownOrMissingSubcommand(
112+
legacyExecutablePath.lastPathComponent,
113+
legacyExecutablePath
114+
.deletingLastPathComponent()
115+
.withUnsafeFileSystemRepresentation { String(cString: $0!) })
112116
}
113117
}
114118

@@ -127,7 +131,7 @@ do {
127131

128132
guard let subcommandPath = subcommandPath,
129133
localFileSystem.exists(subcommandPath) else {
130-
throw Driver.Error.unknownOrMissingSubcommand(subcommand)
134+
throw Driver.Error.unknownOrMissingSubcommand(subcommand, nil)
131135
}
132136

133137
// Pass the full path to subcommand executable.

0 commit comments

Comments
 (0)