Skip to content

Add more standardized error definitions #365

@joy4eg

Description

@joy4eg

It would be nice to have some predefined errors like:

var (
    ErrNoCertAvailable = errors.New("no certificate available")
    ErrSomethingWrong  = errors.New("...")
    // TBD.
)

So the client code could do:

if errors.Is(err, certmagic.ErrNoCertAvailable) { // Do something here }

So far we have some tricky logic that selects a certificate for the connection, which involves certmagic, static certificates, and some internal tools.
Having the ability to check for particular error would be really helpful.

What would you like to have changed?

return Certificate{}, fmt.Errorf("no certificate available for '%s'", name)

Why is this feature a useful, necessary, and/or important addition to this project?

It allows checking for the specific errors via generic methods like errors.Is

What alternatives are there, or what are you doing in the meantime to work around the lack of this feature?

if strings.Contains(err.Error(), "no certificate available") { ... } 

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestRequest for new feature or functionality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions