Skip to content

Commit 51fffb6

Browse files
MahdiBMhassila
andauthored
fix(patch): Use String(reflecting: error) for printing errors (#290)
## Description A few (mostly server side) packages like PostgresNIO have a generic `description` in their errors, while providing the full error info in `debugDescription`. Using `String(reflecting: error)` we can make sure the `debugDescription` is preferred when transforming the error into an `String`. Sample error: ``` Benchmark MyBenchmark failed with PostgresDecodingError – Generic description to prevent accidental leakage of sensitive data. For debugging details, use String(reflecting: error). ``` ## How Has This Been Tested? Please describe the tests that you ran to verify your changes. ## Minimal checklist: - [x] I have performed a self-review of my own code - [ ] I have added `DocC` code-level documentation for any public interfaces exported by the package - [ ] I have added unit and/or integration tests that prove my fix is effective or that my feature works Co-authored-by: Joakim Hassila <[email protected]>
1 parent df62bb1 commit 51fffb6

File tree

7 files changed

+13
-13
lines changed

7 files changed

+13
-13
lines changed

Plugins/BenchmarkTool/BenchmarkTool+Baselines.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ extension BenchmarkTool {
223223
print("Removing baseline '\(baselineName)' for \(target)")
224224
try filemanager.removeItem(atPath: file.description)
225225
} catch {
226-
print("Failed to remove file \(file), error \(error)")
226+
print("Failed to remove file \(file), error \(String(reflecting: error))")
227227
print("Give benchmark plugin permissions to delete files by running with e.g.:")
228228
print("")
229229
print("swift package --allow-writing-to-package-directory benchmark baseline delete")
@@ -376,7 +376,7 @@ extension BenchmarkTool {
376376
baseline = try JSONDecoder().decode(BenchmarkBaseline.self, from: Data(readBytes))
377377

378378
} catch {
379-
print("Failed to open file for reading \(path) [\(error)]")
379+
print("Failed to open file for reading \(path) [\(String(reflecting: error))]")
380380
}
381381
}
382382
} catch {

Plugins/BenchmarkTool/BenchmarkTool+Export.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ extension BenchmarkTool {
7373
_ = try fd.write(UnsafeRawBufferPointer($0))
7474
}
7575
} catch {
76-
print("Failed to write to file \(outputPath) [\(error)]")
76+
print("Failed to write to file \(outputPath) [\(String(reflecting: error))]")
7777
}
7878
}
7979
} catch {
80-
print("Failed to close fd for \(outputPath) after write [\(error)].")
80+
print("Failed to close fd for \(outputPath) after write [\(String(reflecting: error))].")
8181
}
8282
} catch {
8383
if errno == EPERM {
@@ -127,11 +127,11 @@ extension BenchmarkTool {
127127
_ = try fd.write(rawBuffer)
128128
}
129129
} catch {
130-
print("Failed to write to file \(outputPath) [\(error)]")
130+
print("Failed to write to file \(outputPath) [\(String(reflecting: error))]")
131131
}
132132
}
133133
} catch {
134-
print("Failed to close fd for \(outputPath) after write [\(error)].")
134+
print("Failed to close fd for \(outputPath) after write [\(String(reflecting: error))].")
135135
}
136136
} catch {
137137
if errno == EPERM {

Plugins/BenchmarkTool/BenchmarkTool+ReadP90AbsoluteThresholds.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ extension BenchmarkTool {
7979
}
8080
}
8181
} catch {
82-
print("Failed to read file at \(path) [\(error)] \(Errno(rawValue: errno).description)")
82+
print("Failed to read file at \(path) [\(String(reflecting: error))] \(Errno(rawValue: errno).description)")
8383
}
8484
}
8585
} catch {

Plugins/BenchmarkTool/BenchmarkTool.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ struct BenchmarkTool: AsyncParsableCommand {
385385

386386
try write(.end)
387387
} catch {
388-
print("Process failed: \(error)")
388+
print("Process failed: \(String(reflecting: error))")
389389
}
390390

391391
if status == 0 {

Sources/Benchmark/Benchmark+ConvenienceInitializers.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public extension Benchmark {
6767
let setupResult = benchmark.setupState! as! SetupResult // swiftlint:disable:this force_cast
6868
try closure(benchmark, setupResult)
6969
} catch {
70-
benchmark.error("Benchmark \(name) failed with \(error)")
70+
benchmark.error("Benchmark \(name) failed with \(String(reflecting: error))")
7171
}
7272
}, teardown: teardown)
7373

@@ -94,7 +94,7 @@ public extension Benchmark {
9494
let setupResult = benchmark.setupState! as! SetupResult // swiftlint:disable:this force_cast
9595
try await closure(benchmark, setupResult)
9696
} catch {
97-
benchmark.error("Benchmark \(name) failed with \(error)")
97+
benchmark.error("Benchmark \(name) failed with \(String(reflecting: error))")
9898
}
9999
}, teardown: teardown)
100100

Sources/Benchmark/Benchmark.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ public final class Benchmark: Codable, Hashable { // swiftlint:disable:this type
240240
do {
241241
try closure(benchmark)
242242
} catch {
243-
benchmark.error("Benchmark \(name) failed with \(error)")
243+
benchmark.error("Benchmark \(name) failed with \(String(reflecting: error))")
244244
}
245245
}, setup: setup, teardown: teardown)
246246
}
@@ -261,7 +261,7 @@ public final class Benchmark: Codable, Hashable { // swiftlint:disable:this type
261261
do {
262262
try await closure(benchmark)
263263
} catch {
264-
benchmark.error("Benchmark \(name) failed with \(error)")
264+
benchmark.error("Benchmark \(name) failed with \(String(reflecting: error))")
265265
}
266266
}, setup: setup, teardown: teardown)
267267
}

Sources/Benchmark/BenchmarkRunner.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ public struct BenchmarkRunner: AsyncParsableCommand, BenchmarkRunnerReadWrite {
196196
try await hook?()
197197
}
198198
} catch {
199-
try channel.write(.error("Benchmark.teardown or local benchmark teardown failed: \(error)"))
199+
try channel.write(.error("Benchmark.teardown or local benchmark teardown failed: \(String(reflecting: error))"))
200200
return
201201
}
202202

0 commit comments

Comments
 (0)