Skip to content

Commit 6aab24a

Browse files
committed
Log deprecated Router warning once per process
The deprecated `Router`/`RouterError` compatibility shim from `@fedify/fedify/federation` logged a deprecation warning on every wrapped call. For applications that keep the compatibility class during migration, this could flood logs. Consolidate both warnings into a single module-level one-shot `warnDeprecated()` guard so the migration signal is emitted at most once per process, and add a regression test asserting the warning is logged at most once across many wrapped calls and the error path. #758 (comment) Assisted-by: Claude Code:claude-opus-4-7
1 parent 8544065 commit 6aab24a

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

packages/fedify/src/federation/router.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ import { getLogger } from "@logtape/logtape";
1212

1313
const logger = getLogger(["fedify", "federation", "router", "deprecated"]);
1414

15+
let deprecationWarned = false;
16+
17+
function warnDeprecated(): void {
18+
if (deprecationWarned) return;
19+
deprecationWarned = true;
20+
logger.warn(
21+
"The `Router` and `RouterError` classes from `@fedify/fedify` are " +
22+
"deprecated. Please use `Router` from `@fedify/uri-template` instead.",
23+
);
24+
}
25+
1526
/**
1627
* Options for the {@link Router}.
1728
* @since 0.12.0
@@ -159,19 +170,13 @@ export class RouterError extends _RouterError {
159170
*/
160171
constructor(message: string) {
161172
super(message);
162-
logger.warn(
163-
"The `RouterError` class from `@fedify/fedify` is deprecated." +
164-
" Please use `Router` from `@fedify/uri-template` instead.",
165-
);
173+
warnDeprecated();
166174
}
167175
}
168176

169177
function convertRouterError<T>(func: () => T): T {
170178
try {
171-
logger.warn(
172-
"The `Router` class from `@fedify/fedify` is deprecated." +
173-
" Please use `Router` from `@fedify/uri-template` instead.",
174-
);
179+
warnDeprecated();
175180
return func();
176181
} catch (error) {
177182
if (error instanceof _RouterError) {

0 commit comments

Comments
 (0)