From 984cfe358d3558f75040ab2f7a043a454f6df84c Mon Sep 17 00:00:00 2001 From: Hazelnoot Date: Thu, 14 Nov 2024 18:47:28 -0500 Subject: [PATCH 1/3] reduce log spam from `updateFeatured` --- .../core/activitypub/models/ApPersonService.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index 2119c41569..d2f5b64119 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -7,6 +7,7 @@ import { Inject, Injectable } from '@nestjs/common'; import promiseLimit from 'promise-limit'; import { DataSource } from 'typeorm'; import { ModuleRef } from '@nestjs/core'; +import { AbortError } from 'node-fetch'; import { DI } from '@/di-symbols.js'; import type { FollowingsRepository, InstancesRepository, MiMeta, UserProfilesRepository, UserPublickeysRepository, UsersRepository } from '@/models/_.js'; import type { Config } from '@/config.js'; @@ -482,7 +483,13 @@ export class ApPersonService implements OnModuleInit { } //#endregion - await this.updateFeatured(user.id, resolver).catch(err => this.logger.error(err)); + await this.updateFeatured(user.id, resolver).catch(err => { + if (err instanceof AbortError || (err instanceof StatusError && err.isRetryable)) { + this.logger.warn(`Failed to update featured notes: ${err.name}: ${err.message}`); + } else { + this.logger.error('Failed to update featured notes:', err); + } + }); return user; } @@ -647,7 +654,13 @@ export class ApPersonService implements OnModuleInit { { followerSharedInbox: person.sharedInbox ?? person.endpoints?.sharedInbox }, ); - await this.updateFeatured(exist.id, resolver).catch(err => this.logger.error(err)); + await this.updateFeatured(exist.id, resolver).catch(err => { + if (err instanceof AbortError || (err instanceof StatusError && err.isRetryable)) { + this.logger.warn(`Failed to update featured notes: ${err.name}: ${err.message}`); + } else { + this.logger.error('Failed to update featured notes:', err); + } + }); const updated = { ...exist, ...updates }; From fedf0d7e20e615485b79b393e597ed2619577df0 Mon Sep 17 00:00:00 2001 From: Hazelnoot Date: Thu, 14 Nov 2024 20:32:59 -0500 Subject: [PATCH 2/3] further reduce log spam from `updateFeatured` errors --- .../activitypub/models/ApPersonService.ts | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index d2f5b64119..6754c6c41b 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -483,13 +483,7 @@ export class ApPersonService implements OnModuleInit { } //#endregion - await this.updateFeatured(user.id, resolver).catch(err => { - if (err instanceof AbortError || (err instanceof StatusError && err.isRetryable)) { - this.logger.warn(`Failed to update featured notes: ${err.name}: ${err.message}`); - } else { - this.logger.error('Failed to update featured notes:', err); - } - }); + await this.updateFeatured(user.id, resolver).catch(err => console.error(err)); return user; } @@ -654,13 +648,7 @@ export class ApPersonService implements OnModuleInit { { followerSharedInbox: person.sharedInbox ?? person.endpoints?.sharedInbox }, ); - await this.updateFeatured(exist.id, resolver).catch(err => { - if (err instanceof AbortError || (err instanceof StatusError && err.isRetryable)) { - this.logger.warn(`Failed to update featured notes: ${err.name}: ${err.message}`); - } else { - this.logger.error('Failed to update featured notes:', err); - } - }); + await this.updateFeatured(exist.id, resolver).catch(err => console.error(err)); const updated = { ...exist, ...updates }; @@ -735,7 +723,15 @@ export class ApPersonService implements OnModuleInit { const _resolver = resolver ?? this.apResolverService.createResolver(); // Resolve to (Ordered)Collection Object - const collection = await _resolver.resolveCollection(user.featured); + const collection = await _resolver.resolveCollection(user.featured).catch(err => { + if (err instanceof AbortError || err instanceof StatusError) { + this.logger.warn(`Failed to update featured notes: ${err.name}: ${err.message}`); + } else { + this.logger.error('Failed to update featured notes:', err); + } + }); + if (!collection) return; + if (!isCollectionOrOrderedCollection(collection)) throw new Error('Object is not Collection or OrderedCollection'); // Resolve to Object(may be Note) arrays From dcd5b6d972809bf5d4f6f0ae3f1d7d1e9edab54b Mon Sep 17 00:00:00 2001 From: Hazelnoot Date: Sun, 17 Nov 2024 09:01:59 -0500 Subject: [PATCH 3/3] replace `console.error` with `this.logger.error` (merge error) --- .../backend/src/core/activitypub/models/ApPersonService.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index 6754c6c41b..b03d6b1853 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -483,7 +483,7 @@ export class ApPersonService implements OnModuleInit { } //#endregion - await this.updateFeatured(user.id, resolver).catch(err => console.error(err)); + await this.updateFeatured(user.id, resolver).catch(err => this.logger.error(err)); return user; } @@ -648,7 +648,7 @@ export class ApPersonService implements OnModuleInit { { followerSharedInbox: person.sharedInbox ?? person.endpoints?.sharedInbox }, ); - await this.updateFeatured(exist.id, resolver).catch(err => console.error(err)); + await this.updateFeatured(exist.id, resolver).catch(err => this.logger.error(err)); const updated = { ...exist, ...updates };