From 5042d49935baa310e94315131280f62159c44182 Mon Sep 17 00:00:00 2001 From: KernelDeimos Date: Thu, 23 May 2024 18:40:41 -0400 Subject: [PATCH] Simplify debugging runtime config object changes --- packages/backend/src/config.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/config.js b/packages/backend/src/config.js index f37ee3b0..0ba65cce 100644 --- a/packages/backend/src/config.js +++ b/packages/backend/src/config.js @@ -175,9 +175,25 @@ const config_pointer = {}; // We'd like to store values changed at runtime separately // for easier runtime debugging { - const config_runtime_values = {}; + const config_runtime_values = { + $: 'runtime-values' + }; config_runtime_values.__proto__ = config_to_export; config_to_export = config_runtime_values + + // These can be difficult to find and cause painful + // confusing issues, so we log any time this happens + config_to_export = new Proxy(config_to_export, { + set: (target, prop, value, receiver) => { + console.log( + '\x1B[36;1mCONFIGURATION MUTATED AT RUNTIME\x1B[0m', + prop, 'to', value + ); + // console.log(new Error('stack trace to find configuration mutation')); + target[prop] = value; + return true; + } + }) } -module.exports = config_to_export; \ No newline at end of file +module.exports = config_to_export;