Skip to content

Commit bde3be7

Browse files
committed
Validate scoped filter registry
Reject scoped configurations whose filters registry is present but not an object, so invalid user input fails with ConfigError instead of reaching Object.values() with a primitive value. #188 (comment) Assisted-by: Codex:gpt-5.5
1 parent 77fa6f1 commit bde3be7

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

packages/logtape/src/config.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,15 @@ test("withConfig() rejects invalid scoped configuration", async () => {
582582
} as never, () => {}),
583583
ConfigError,
584584
);
585+
await assert.rejects(
586+
() =>
587+
withConfig({
588+
sinks: {},
589+
filters: "filter",
590+
loggers: [],
591+
} as never, () => {}),
592+
ConfigError,
593+
);
585594
await assert.rejects(
586595
() =>
587596
withConfig({

packages/logtape/src/scoped-config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ export function compileScopedConfig<
7777
if (!Array.isArray(config.loggers)) {
7878
throw createError("Configuration must include a loggers array.");
7979
}
80+
if (config.filters !== undefined && !isObjectLike(config.filters)) {
81+
throw createError("Configuration filters must be an object.");
82+
}
8083

8184
const nodes = new Map<string, CompiledScopedLogger>();
8285
const configuredCategories = new Set<string>();

0 commit comments

Comments
 (0)