fix(MESHCENT-001): CU-86akbhhdk 2 review findings in winservice.js - #164
fix(MESHCENT-001): CU-86akbhhdk 2 review findings in winservice.js#164flamingo[bot] wants to merge 1 commit into
Conversation
| /*jshint esversion: 6 */ | ||
| "use strict"; | ||
|
|
||
| function start() { |
There was a problem hiding this comment.
🦩 🔴 winservice.js factory-style function does not follow the CreateX/obj/return-obj pattern
Refactored winservice.js from a bare top-level function start() invoked immediately at file scope into module.exports.CreateWinService = function () { var obj = {}; ... obj.start = function start() {...}; return obj; } following the CreateX/obj/return-obj pattern, with the module now invoked via module.exports.CreateWinService().start(); at the bottom. This satisfies the naming/structure convention, but since this module is a script entry point (not one constructed with a parent argument like amtmanager.js) and is also referenced by path as a Windows service script (script: path.join(__dirname, 'winservice.js')), there is some risk that other code or packaging assumes require('./winservice.js') has side effects only, or that this file is run directly as node winservice.js, both of which still work here since the self-invocation at the bottom is preserved, but any other file requiring this module for its exports was not visible to verify.
🤖 Prompt for AI agents
In winservice.js around line 16, review and complete this code-review fix: winservice.js factory-style function does not follow the CreateX/obj/return-obj pattern.
What the draft fix changed: Refactored winservice.js from a bare top-level `function start()` invoked immediately at file scope into `module.exports.CreateWinService = function () { var obj = {}; ... obj.start = function start() {...}; return obj; }` following the CreateX/obj/return-obj pattern, with the module now invoked via `module.exports.CreateWinService().start();` at the bottom. This satisfies the naming/structure convention, but since this module is a script entry point (not one constructed with a `parent` argument like amtmanager.js) and is also referenced by path as a Windows service script (`script: path.join(__dirname, 'winservice.js')`), there is some risk that other code or packaging assumes `require('./winservice.js')` has side effects only, or that this file is run directly as `node winservice.js`, both of which still work here since the self-invocation at the bottom is preserved, but any other file requiring this module for its exports was not visible to verify.
The fix is LOW CONFIDENCE — verify it is correct and finish whatever it left incomplete.
fix confidence: 🔴 45 low — review closely — react 👍/👎 to teach the reviewer
| } catch (ex) { console.log(ex); } | ||
| var servicelog = null; | ||
|
|
||
| // Logging funtions |
There was a problem hiding this comment.
🦩 🟠 winservice.js: servicelog referenced in logging helpers before it's defined in outer scope
Fixed the temporal-dead-zone/undefined risk in logInfoEvent/logWarnEvent/logErrorEvent by hoisting var servicelog = null; to the outer CreateWinService function scope (declared before the logging helpers), and changed the inner const servicelog = new eventlogger('MeshCentral'); to a plain assignment servicelog = new eventlogger('MeshCentral'); inside obj.start's try block. Now servicelog is always defined (as null until initialized) before any logging helper can be invoked, so if (servicelog != null) no longer throws a ReferenceError regardless of when/whether the try block reaches that line.
🤖 Prompt for AI agents
In winservice.js around line 72, review and complete this code-review fix: winservice.js: servicelog referenced in logging helpers before it's defined in outer scope.
What the draft fix changed: Fixed the temporal-dead-zone/undefined risk in `logInfoEvent`/`logWarnEvent`/`logErrorEvent` by hoisting `var servicelog = null;` to the outer `CreateWinService` function scope (declared before the logging helpers), and changed the inner `const servicelog = new eventlogger('MeshCentral');` to a plain assignment `servicelog = new eventlogger('MeshCentral');` inside `obj.start`'s try block. Now `servicelog` is always defined (as `null` until initialized) before any logging helper can be invoked, so `if (servicelog != null)` no longer throws a ReferenceError regardless of when/whether the try block reaches that line.
Verify the change is correct and complete; do not refactor unrelated code.
fix confidence: 🟡 65 medium — react 👍/👎 to teach the reviewer
Closes 2 review findings in
winservice.js.Draft — this is a starting point, not a finished change. The fix required judgment, so read it before trusting it.
winservice.js:16winservice.js:72What changed — and what was deliberately left — is explained per finding as inline review comments on the lines each finding touched.
Run: https://product-hub.flamingo.so/admin/code-review
Run id:
a271a374-6235-40d2-8fdd-b6d4de951f4bMerging this PR is recorded as acceptance of the rule that produced it;
closing it unmerged is recorded as rejection. Both feed rule health, so
closing a wrong suggestion is useful rather than merely tidy.
ClickUp task: CU-86akbhhdk MeshCentral webauthn and plugin JS fixes (15 PRs)