-
-
Notifications
You must be signed in to change notification settings - Fork 137
Lower suppressed vocabulary log level #1035
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
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,8 @@ | ||
| --- | ||
| links: | ||
| '#1035': https://github.com/fedify-dev/fedify/pull/1035 | ||
| '#933': https://github.com/fedify-dev/fedify/issues/933 | ||
| --- | ||
| - Changed suppressed vocabulary fetch and parsing failures to log at the | ||
| warning level so that intentionally handled failures are not reported as | ||
| application errors. [[#933], [#1035] by Jae Hui Hong] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,6 +46,13 @@ export interface DocumentLoaderOptions { | |
| * @since 1.8.0 | ||
| */ | ||
| signal?: AbortSignal; | ||
|
|
||
| /** | ||
| * Whether to lower error-level logs for recoverable document loading | ||
| * failures to warning-level logs. The loader still throws the error. | ||
| * @default `false` | ||
| */ | ||
| suppressError?: boolean; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -171,6 +178,7 @@ async function readBoundedText( | |
| * @param url The URL of the document to load. | ||
| * @param response The response to get the document from. | ||
| * @param fetch The function to fetch the document. | ||
| * @param options The options for loading the document. | ||
| * @returns The loaded remote document. | ||
| * @throws {FetchError} If the response is not OK. | ||
| * @internal | ||
|
|
@@ -182,18 +190,31 @@ export async function getRemoteDocument( | |
| url: string, | ||
| options?: DocumentLoaderOptions, | ||
| ) => Promise<RemoteDocument>, | ||
| options?: DocumentLoaderOptions, | ||
| ): Promise<RemoteDocument> { | ||
| const documentUrl = response.url === "" ? url : response.url; | ||
| const docUrl = new URL(documentUrl); | ||
| if (!response.ok) { | ||
| logger.error( | ||
| "Failed to fetch document: {status} {url} {headers}", | ||
| { | ||
| status: response.status, | ||
| url: documentUrl, | ||
| headers: Object.fromEntries(response.headers.entries()), | ||
| }, | ||
| ); | ||
| if (options?.suppressError) { | ||
|
Member
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. Please apply |
||
| logger.warn( | ||
| "Failed to fetch document: {status} {url} {headers}", | ||
| { | ||
| status: response.status, | ||
| url: documentUrl, | ||
| headers: Object.fromEntries(response.headers.entries()), | ||
| }, | ||
| ); | ||
| } else { | ||
| logger.error( | ||
| "Failed to fetch document: {status} {url} {headers}", | ||
| { | ||
| status: response.status, | ||
| url: documentUrl, | ||
| headers: Object.fromEntries(response.headers.entries()), | ||
| }, | ||
| ); | ||
| } | ||
|
|
||
| throw new FetchError( | ||
| documentUrl, | ||
| `HTTP ${response.status}: ${documentUrl}`, | ||
|
|
@@ -242,7 +263,7 @@ export async function getRemoteDocument( | |
| "Found alternate document: {alternateUrl} from {url}", | ||
| { alternateUrl: altUri.href, url: documentUrl }, | ||
| ); | ||
| return await fetch(altUri.href); | ||
| return await fetch(altUri.href, options); | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -302,7 +323,7 @@ export async function getRemoteDocument( | |
| "Found alternate document: {alternateUrl} from {url}", | ||
| { alternateUrl: attribs.href, url: documentUrl }, | ||
| ); | ||
| return await fetch(new URL(attribs.href, docUrl).href); | ||
| return await fetch(new URL(attribs.href, docUrl).href, options); | ||
| } | ||
| } | ||
| try { | ||
|
|
@@ -456,7 +477,12 @@ export function getDocumentLoader( | |
| return await load(redirectUrl, options, redirected + 1, visited); | ||
| } | ||
|
|
||
| const result = await getRemoteDocument(currentUrl, response, load); | ||
| const result = await getRemoteDocument( | ||
| currentUrl, | ||
| response, | ||
| load, | ||
| options, | ||
| ); | ||
| span.setAttribute("docloader.document_url", result.documentUrl); | ||
| if (result.contextUrl != null) { | ||
| span.setAttribute("docloader.context_url", result.contextUrl); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also honor
suppressErrorwhen URL validation rejects a private address, in both the default and authenticated document loaders. I testedhttp://127.0.0.1/privatewith each loader: the accessor returnsnullwithsuppressError: true, butDisallowed private URL: {url}is still logged at error level. No network request is made. Please retain the address checks and thrown exceptions, lower this log to warning only for suppressed calls, and add regression coverage for both loaders.