caddyserver / caddyserver/certmagic

Add more standardized error definitions

Open
#365 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

feature request
Dominant language
Go
Stars
5.6k
Forks
354
Avg merge
9d 23h
Merged PRs (30d)
3

Description

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?

https://github.com/caddyserver/certmagic/blob/d2a72863e63a7f37fc4bb39859614807d550b9df/handshake.go#L404

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") { ... } 

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at handshake.go around line 404 and trace the certificate-selection errors returned through certmagic and related certificate sources. Identify the stable conditions that should have predefined errors, then verify that callers can distinguish them with errors.Is. Done means the selected errors are exposed as package definitions and the relevant returned errors support those checks.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.