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

Provide support for "self describing" Error conforming types #116

Open
nbrooke opened this issue Dec 23, 2023 · 0 comments
Open

Provide support for "self describing" Error conforming types #116

nbrooke opened this issue Dec 23, 2023 · 0 comments

Comments

@nbrooke
Copy link
Member

nbrooke commented Dec 23, 2023

Right now all logging of error types must take the form clog.error(message, error), requiring providing a message. But for strongly typed errors, the "message" may just be a restatement of the "type" of the error to some degree, i.e.

func operationFailed(_ error: NetworkError) {
    clog.error("Network error", error)
}

func otherOperationFailed(_ error: SpecificError) {
    switch error {
      case .a : clog.error("failure A", error)
      case .b : clog.error("failure B", error)
    }
}

On one project, we did add direct support for this sort of thing at the app level by adding a type that provides a description, something like:

protocol LoggableError: Error {
   var typeDescription: StaticString { get } 
}

which would allow adding a

func error(_ selfDescribingError: LoggableError) {
  error(selfDescribingError.typeDescription, selfDescribingError)
}

that doesn't need a message. It might be useful to support this at the Steamclog level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant