Repository navigation
Add error message to account registration error - #9233
Conversation
There was a problem hiding this comment.
Thanks for picking this up.
I've opted to have the first character of the error message to be lower case, as it's the first character after a colon. For me personally, that has to be lower case instead of upper case.
I think if we choose to do this, we should do it consistently across Certbot's error handling. At the moment, it looks like all cases of errors following a colon, show the error verbatim.
I am also a little skeptical that it won't sometimes do the wrong thing. e.g. if the first word in the error message is ACME, you would get aCME, which is weirdly reminiscent of ASN.1 ;).
|
Note that the error "Server requires external account binding. (...)" is actually a message from
Addressed the above 🙂 |
|
Code is a little bit more complicated now to also catch errors from the acme library. It raises An example would be an |
| if isinstance(err, acme_messages.Error): | ||
| # `acme.messages.Error` has more details than `certbot.errors.Error`, so we | ||
| # can use these details to provide a human readable error message: | ||
| if err.detail: | ||
| # `detail` contains a human readable error message provided by the | ||
| # ACME server. | ||
| err_msg = err.detail | ||
| elif err.description: | ||
| # If `detail` is not provided, the `acme` library can return a human | ||
| # readable error message based on the error type in `description`. | ||
| err_msg = err.description | ||
| else: | ||
| # If no human readable error message can be found, the ACME error type | ||
| # is presented to the user. | ||
| err_msg = str(err) | ||
| else: | ||
| err_msg = str(err) |
There was a problem hiding this comment.
Sorry for the delay reviewing this, it's been hard to find time.
For consistency and simplicity's sake, ISTM that we can just take advantage of __str__ on acme.messages.Error:
Lines 137 to 141 in 142fcad
Would you be able to give that a try and see whether str(err) does the trick? I'd like to avoid having one-off code related to display here. If we do end up needing a new way to display errors to users, we should deal with it in a global way.
There was a problem hiding this comment.
I noticed that function too when looking at it. But if we use str(err) it would mean a Certbot raised error would be a relative simple error message which would be very different than an error message raised by the ACME client, as that would be a long line with all the different fields separated by " :: ". To me, that difference was too big, so I build the code above to make it more the same with regard to a user experience: a simple to understand error message.
But of course KISS is always a good argument 😉
There was a problem hiding this comment.
That's reasonable, and there's always the option to change what __str__ does, if we do decide it's unreadable.
https://datatracker.ietf.org/doc/html/rfc7807#section-3.1 is pretty clear that only title and detail are supposed to be human-readable.
I also recall reading a comment on the Certbot repo years ago from one of Boulder's developers, calling Certbot out for the way the description property is interpreting the problem type and mapping it into this dictionary. This was a misinterpretation of the ACME document, I think.
tl;dr; I'm sure we'd be open to changing it, but let's kick it to another issue.
There was a problem hiding this comment.
I'll make this code as simple as possible, so we can change anything, if required, from a single point in __str__() in the future.
|
I did leave the distinction between a Certbot generated error and ACME server generated error and I removed the "Error returned by the ACME server: " part for a Certbot generated error, as that was incorrect before. Also note that the contents |
| except (errors.Error, acme_messages.Error) as err: | ||
| logger.debug("", exc_info=True) | ||
| if isinstance(err, acme_messages.Error): | ||
| err_msg = f"Error returned by the ACME server: {str(err)}" |
There was a problem hiding this comment.
Lol:
certbot/certbot/certbot/_internal/log.py
Lines 367 to 370 in 142fcad
I am starting to wonder we should change this properly, now. I'm actually not sure whether messing with __str__ would be a breaking change, but we can always add a new method for display purposes. Let me find out.
There was a problem hiding this comment.
Hm, that code assumes that an ACME error always contains all three properties. But in acme.messages.Error all three properties have omitempty=True set. So if the ACME server doesn't e.g. provide the title for some reason, str(err) would only provide two partitions separated by :: , right? Not sure if Boulder actually does that and not sure if it's allowed by the RFCs, but still.
Also, not sure how it's tied into this PR.
There was a problem hiding this comment.
I would really like to not show the error type and the description field, but let's leave it for now. This PR fixes the problem it was supposed to, albeit slightly verbosely.
Put everything in this commit instead of using the "Commit suggestion" feat on Github, which would resolve in 4 different tiny commits.
Fixes #9231
I've opted to have the first character of the error message to be lower case, as it's the first character after a colon. For me personally, that has to be lower case instead of upper case.