Skip to content

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

Description

@nbrooke

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions