Skip to content

Commit 1da570e

Browse files
committed
review comments
1 parent b87b3e5 commit 1da570e

File tree

2 files changed

+29
-27
lines changed

2 files changed

+29
-27
lines changed

Plugins/GRPCProtobufGeneratorCommand/CommandPluginError.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ enum CommandPluginError: Error {
2323
case conflictingFlags(String, String)
2424
case generationFailure(
2525
errorDescription: String,
26-
executable: String?,
27-
arguments: [String]?,
26+
executable: String,
27+
arguments: [String],
2828
stdErr: String?
2929
)
3030
case tooManyParameterSeparators
@@ -46,16 +46,16 @@ extension CommandPluginError: CustomStringConvertible {
4646
case .conflictingFlags(let flag1, let flag2):
4747
return "Provided flags conflict: '\(flag1)' and '\(flag2)'."
4848
case .generationFailure(let errorDescription, let executable, let arguments, let stdErr):
49-
var message = "Code generation failed with: \(errorDescription)."
50-
if let executable {
51-
message += "\n\tExecutable: \(executable)"
52-
}
53-
if let arguments {
54-
message += "\n\tArguments: \(arguments.joined(separator: " "))"
55-
}
49+
var message = """
50+
Code generation failed with: \(errorDescription).
51+
\tExecutable: \(executable)
52+
\tArguments: \(arguments.joined(separator: " "))
53+
"""
5654
if let stdErr {
57-
message += "\n\tprotoc error output:"
58-
message += "\n\t\(stdErr)"
55+
message += """
56+
\n\tprotoc error output:
57+
\t\(stdErr)
58+
"""
5959
}
6060
return message
6161
case .tooManyParameterSeparators:

Plugins/GRPCProtobufGeneratorCommand/Plugin.swift

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ struct GRPCProtobufGeneratorCommandPlugin {
129129
dryRun: commandConfig.dryRun
130130
)
131131

132-
if !commandConfig.dryRun {
132+
if !commandConfig.dryRun, commandConfig.verbose {
133133
Stderr.print("Generated gRPC Swift files for \(inputFiles.joined(separator: ", ")).")
134134
}
135135
}
@@ -152,7 +152,7 @@ struct GRPCProtobufGeneratorCommandPlugin {
152152
dryRun: commandConfig.dryRun
153153
)
154154

155-
if !commandConfig.dryRun {
155+
if !commandConfig.dryRun, commandConfig.verbose {
156156
Stderr.print(
157157
"Generated protobuf message Swift files for \(inputFiles.joined(separator: ", "))."
158158
)
@@ -212,21 +212,23 @@ func executeProtocInvocation(
212212

213213
try printProtocOutput(outputPipe, verbose: verbose)
214214

215-
guard process.terminationReason == .exit && process.terminationStatus == 0 else {
216-
let stdErr: String?
217-
if let errorData = try errorPipe.fileHandleForReading.readToEnd() {
218-
stdErr = String(decoding: errorData, as: UTF8.self)
219-
} else {
220-
stdErr = nil
221-
}
222-
let problem = "\(process.terminationReason):\(process.terminationStatus)"
223-
throw CommandPluginError.generationFailure(
224-
errorDescription: problem,
225-
executable: executableURL.absoluteStringNoScheme,
226-
arguments: arguments,
227-
stdErr: stdErr
228-
)
215+
if process.terminationReason == .exit && process.terminationStatus == 0 {
216+
return
217+
}
218+
219+
let stdErr: String?
220+
if let errorData = try errorPipe.fileHandleForReading.readToEnd() {
221+
stdErr = String(decoding: errorData, as: UTF8.self)
222+
} else {
223+
stdErr = nil
229224
}
225+
let problem = "\(process.terminationReason):\(process.terminationStatus)"
226+
throw CommandPluginError.generationFailure(
227+
errorDescription: problem,
228+
executable: executableURL.absoluteStringNoScheme,
229+
arguments: arguments,
230+
stdErr: stdErr
231+
)
230232

231233
return
232234
}

0 commit comments

Comments
 (0)