Repository navigation
Add diagnostics to WebFinger lookups #1296
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
base: main
Are you sure you want to change the base?
Changes from all commits
aa8ac01
f86bd10
cbc8425
2a60fb4
01f17a7
adbcaa2
110e47e
e629393
620c092
9300178
564e945
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| --- | ||
| links: | ||
| '#1296': https://github.com/fedify-dev/fedify/pull/1296 | ||
| '#897': https://github.com/fedify-dev/fedify/issues/897 | ||
| --- | ||
| - Changed the `fedify webfinger` command's error message when a lookup | ||
| fails. It now explains why—resource not found, a network error, a | ||
| malformed response, or an unexpected server error—instead of always | ||
| reporting the resource as not found. [[#897], [#1296] by Jae-Hyuk-Jang] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| --- | ||
| links: | ||
| '#1296': https://github.com/fedify-dev/fedify/pull/1296 | ||
| '#897': https://github.com/fedify-dev/fedify/issues/897 | ||
| --- | ||
| - Added a `withDiagnostics` option to `lookupWebFinger()`. When turned on, | ||
| the function returns an object describing why the lookup failed—a | ||
| network error, a malformed response, an unexpected server error, or the | ||
| resource genuinely not existing—instead of returning `null` for every | ||
| failure. `Context.lookupWebFinger()` does not support this option. | ||
| [[#897], [#1296] by Jae-Hyuk-Jang] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -393,6 +393,65 @@ The available options are: | |
| `signal` | ||
| : An `AbortSignal` for cancelling the request. | ||
|
|
||
| `withDiagnostics` | ||
| : *Since Fedify 2.5.0.* Whether to return a `WebFingerLookupOutcome` | ||
| describing why the lookup failed, instead of collapsing every failure | ||
| into `null`. Turned off by default. See | ||
| [*Diagnosing a failed lookup*](#diagnosing-a-failed-lookup) below. | ||
|
|
||
| ### Diagnosing a failed lookup | ||
|
|
||
| *This option is available since Fedify 2.5.0.* | ||
|
|
||
| By default, `lookupWebFinger()` returns `null` for every kind of failure: | ||
| a response saying the resource doesn't exist looks the same as a network | ||
| error or a malformed response. Pass `withDiagnostics: true` to get back a | ||
| `WebFingerLookupOutcome` instead, which explains why the lookup failed: | ||
|
|
||
| ~~~~ typescript twoslash | ||
| import { lookupWebFinger } from "@fedify/webfinger"; | ||
|
|
||
| const outcome = await lookupWebFinger("acct:alice@example.com", { | ||
| withDiagnostics: true, | ||
| }); | ||
|
|
||
| if (outcome.resource != null) { | ||
| console.log("Found:", outcome.resource.subject); | ||
| } else { | ||
| console.log("Failed:", outcome.result); | ||
| } | ||
| ~~~~ | ||
|
|
||
| The `result` field is one of: | ||
|
|
||
| `"found"` | ||
| : The lookup returned a resource descriptor. | ||
|
|
||
| `"not_found"` | ||
| : The remote responded with `404 Not Found` or `410 Gone`. | ||
|
|
||
| `"invalid"` | ||
| : The remote responded with content Fedify could not parse into a | ||
| resource descriptor, or the queried resource was malformed. | ||
|
|
||
| `"network_error"` | ||
| : No HTTP response was received, e.g., the URL was rejected as a private | ||
| address, or the request was aborted. | ||
|
|
||
| `"error"` | ||
| : The remote responded with an unexpected non-2xx HTTP response. | ||
|
|
||
| `withDiagnostics: true` classifies the failures listed above into a | ||
| `WebFingerLookupOutcome`, but it does not turn every failure into one. | ||
| An error `lookupWebFinger()` does not recognize—for example, one while | ||
| reading the response body—still rejects the returned promise, so | ||
| callers must keep handling a rejected promise even with this option | ||
| turned on. | ||
|
|
||
| > [!NOTE] | ||
| > `~Context.lookupWebFinger()` does not support `withDiagnostics`; it always | ||
| > returns the resource descriptor or `null`. | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win Separate the NOTE and TIP callouts for MD028. Line 454 separates the callouts with only a blank line, which triggers the supplied MD028 warning. Add an HTML comment or other non-rendered content between them to clear the warning while keeping the callouts separate. (github.com) 🧰 Tools🪛 markdownlint-cli2 (0.23.3)[warning] 454-454: Blank line inside blockquote (MD028, no-blanks-blockquote) 🤖 Prompt for AI AgentsSource: Linters/SAST tools |
||
| > [!TIP] | ||
| > Use `@fedify/webfinger` when you need a lightweight WebFinger client without | ||
| > the full Fedify framework. If you're already using Fedify, prefer | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.