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(patch): Use String(reflecting: error) for printing errors #290

Merged
merged 3 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
use String(reflecting: error)
  • Loading branch information
MahdiBM committed Oct 8, 2024
commit 1506e1e151c778b41f169a1f2af51cd75afee50e
4 changes: 2 additions & 2 deletions Plugins/BenchmarkTool/BenchmarkTool+Baselines.swift
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ extension BenchmarkTool {
print("Removing baseline '\(baselineName)' for \(target)")
try filemanager.removeItem(atPath: file.description)
} catch {
print("Failed to remove file \(file), error \(error)")
print("Failed to remove file \(file), error \(String(reflecting: error))")
print("Give benchmark plugin permissions to delete files by running with e.g.:")
print("")
print("swift package --allow-writing-to-package-directory benchmark baseline delete")
Expand Down Expand Up @@ -376,7 +376,7 @@ extension BenchmarkTool {
baseline = try JSONDecoder().decode(BenchmarkBaseline.self, from: Data(readBytes))

} catch {
print("Failed to open file for reading \(path) [\(error)]")
print("Failed to open file for reading \(path) [\(String(reflecting: error))]")
}
}
} catch {
Expand Down
8 changes: 4 additions & 4 deletions Plugins/BenchmarkTool/BenchmarkTool+Export.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ extension BenchmarkTool {
_ = try fd.write(UnsafeRawBufferPointer($0))
}
} catch {
print("Failed to write to file \(outputPath) [\(error)]")
print("Failed to write to file \(outputPath) [\(String(reflecting: error))]")
}
}
} catch {
print("Failed to close fd for \(outputPath) after write [\(error)].")
print("Failed to close fd for \(outputPath) after write [\(String(reflecting: error))].")
}
} catch {
if errno == EPERM {
Expand Down Expand Up @@ -127,11 +127,11 @@ extension BenchmarkTool {
_ = try fd.write(rawBuffer)
}
} catch {
print("Failed to write to file \(outputPath) [\(error)]")
print("Failed to write to file \(outputPath) [\(String(reflecting: error))]")
}
}
} catch {
print("Failed to close fd for \(outputPath) after write [\(error)].")
print("Failed to close fd for \(outputPath) after write [\(String(reflecting: error))].")
}
} catch {
if errno == EPERM {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ extension BenchmarkTool {
}
}
} catch {
print("Failed to read file at \(path) [\(error)] \(Errno(rawValue: errno).description)")
print("Failed to read file at \(path) [\(String(reflecting: error))] \(Errno(rawValue: errno).description)")
}
}
} catch {
Expand Down
2 changes: 1 addition & 1 deletion Plugins/BenchmarkTool/BenchmarkTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ struct BenchmarkTool: AsyncParsableCommand {

try write(.end)
} catch {
print("Process failed: \(error)")
print("Process failed: \(String(reflecting: error))")
}

if status == 0 {
Expand Down
4 changes: 2 additions & 2 deletions Sources/Benchmark/Benchmark+ConvenienceInitializers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public extension Benchmark {
let setupResult = benchmark.setupState! as! SetupResult // swiftlint:disable:this force_cast
try closure(benchmark, setupResult)
} catch {
benchmark.error("Benchmark \(name) failed with \(error)")
benchmark.error("Benchmark \(name) failed with \(String(reflecting: error))")
}
}, teardown: teardown)

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

Expand Down
4 changes: 2 additions & 2 deletions Sources/Benchmark/Benchmark.swift
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public final class Benchmark: Codable, Hashable { // swiftlint:disable:this type
do {
try closure(benchmark)
} catch {
benchmark.error("Benchmark \(name) failed with \(error)")
benchmark.error("Benchmark \(name) failed with \(String(reflecting: error))")
}
}, setup: setup, teardown: teardown)
}
Expand All @@ -261,7 +261,7 @@ public final class Benchmark: Codable, Hashable { // swiftlint:disable:this type
do {
try await closure(benchmark)
} catch {
benchmark.error("Benchmark \(name) failed with \(error)")
benchmark.error("Benchmark \(name) failed with \(String(reflecting: error))")
}
}, setup: setup, teardown: teardown)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Benchmark/BenchmarkRunner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public struct BenchmarkRunner: AsyncParsableCommand, BenchmarkRunnerReadWrite {
try await hook?()
}
} catch {
try channel.write(.error("Benchmark.teardown or local benchmark teardown failed: \(error)"))
try channel.write(.error("Benchmark.teardown or local benchmark teardown failed: \(String(reflecting: error))"))
return
}

Expand Down
Loading