Skip to content

Support error chain description with opening indent level #36

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion Sources/ErrorKit/Catching.swift
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ extension Catching {
/// - Returns: The value returned by the operation if successful.
/// - Throws: An instance of `Self` with the original error wrapped in the `caught` case.
public static func `catch`<ReturnType>(
_ operation: () async throws -> ReturnType
_ operation: @Sendable () async throws -> ReturnType
) async throws(Self) -> ReturnType {
do {
return try await operation()
Expand Down
8 changes: 5 additions & 3 deletions Sources/ErrorKit/ErrorKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,12 @@ public enum ErrorKit {
/// 2. Shows the underlying cause (DatabaseError.connectionFailed)
/// 3. Provides the user-friendly message for context (users will report this)
///
/// - Parameter error: The error to describe, potentially containing nested errors
/// - Parameters:
/// - error: The error to describe, potentially containing nested errors
/// - indent: The initial indent string (normally "")
/// - Returns: A formatted string showing the complete error hierarchy with indentation
public static func errorChainDescription(for error: Error) -> String {
return Self.chainDescription(for: error, indent: "", enclosingType: type(of: error))
public static func errorChainDescription(for error: Error, indent: String = "") -> String {
return Self.chainDescription(for: error, indent: indent, enclosingType: type(of: error))
}

private static func chainDescription(for error: Error, indent: String, enclosingType: Any.Type?) -> String {
Expand Down