mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-04 11:52:25 +00:00
Gate EventEmitter listener warnings behind verbose mode
This commit is contained in:
1 parent
7de8eddcbe
commit
487fc740da
3 files changed
+42
-5
No files matched your search
@@ -62,6 +62,7 @@ import {
|
||||
logCountTimeoutCleanupFailure,
|
||||
logRelayCountFailure,
|
||||
} from "./countDiagnostics.js";
|
||||
import "./maxListenerDiagnostics.js";
|
||||
import {
|
||||
publishEventToRelay,
|
||||
publishEventToRelays,
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
// js/nostr/countDiagnostics.js
|
||||
// Centralized helpers for gating high-volume COUNT diagnostics behind
|
||||
// verbose dev mode and deduplicating repeated warnings so the console stays
|
||||
// readable during normal development sessions.
|
||||
// Centralized helpers for gating high-volume COUNT diagnostics (and other
|
||||
// verbose nostr warnings) behind verbose dev mode while deduplicating repeated
|
||||
// messages so the console stays readable during normal development sessions.
|
||||
|
||||
import { devLogger } from "../utils/logger.js";
|
||||
import { isVerboseDevMode } from "../config.js";
|
||||
|
||||
const seenWarningKeys = new Set();
|
||||
|
||||
function isVerboseCountLoggingEnabled() {
|
||||
export function isVerboseDiagnosticsEnabled() {
|
||||
if (typeof window !== "undefined" && window) {
|
||||
const runtimeFlag = window.__BITVID_VERBOSE_DEV_MODE__;
|
||||
if (typeof runtimeFlag === "boolean") {
|
||||
@@ -19,7 +19,7 @@ function isVerboseCountLoggingEnabled() {
|
||||
}
|
||||
|
||||
function logCountWarning(message, args = [], { key, throttle = true } = {}) {
|
||||
if (!isVerboseCountLoggingEnabled()) {
|
||||
if (!isVerboseDiagnosticsEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
// js/nostr/maxListenerDiagnostics.js
|
||||
// Applies verbose-dev-mode-aware defaults to EventEmitter listener limits so
|
||||
// high-volume MaxListeners warnings stay hidden unless explicitly requested.
|
||||
|
||||
import EventEmitter from "events";
|
||||
|
||||
import { isVerboseDiagnosticsEnabled } from "./countDiagnostics.js";
|
||||
|
||||
const DEFAULT_WARNING_THRESHOLD = 10;
|
||||
|
||||
function getTargetMaxListeners() {
|
||||
return isVerboseDiagnosticsEnabled() ? DEFAULT_WARNING_THRESHOLD : 0;
|
||||
}
|
||||
|
||||
function applyMaxListenerPreference() {
|
||||
try {
|
||||
const targetLimit = getTargetMaxListeners();
|
||||
if (typeof EventEmitter.defaultMaxListeners === "number") {
|
||||
if (EventEmitter.defaultMaxListeners !== targetLimit) {
|
||||
EventEmitter.defaultMaxListeners = targetLimit;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
EventEmitter.defaultMaxListeners = targetLimit;
|
||||
} catch (error) {
|
||||
// Swallow errors silently — diagnostics are best-effort and shouldn't
|
||||
// interfere with runtime behavior if the events shim is unavailable.
|
||||
}
|
||||
}
|
||||
|
||||
applyMaxListenerPreference();
|
||||
|
||||
export function refreshMaxListenerPreference() {
|
||||
applyMaxListenerPreference();
|
||||
}
|
||||
Reference in new issue
Block a user