Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions packages/dashmate/src/listr/tasks/startNodeTaskFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const DAPI_PROFILE_SERVICES = {
* @param {getConnectionHost} getConnectionHost
* @param {ensureFileMountExists} ensureFileMountExists
* @param {HomeDir} homeDir
* @param {getConfigProfiles} getConfigProfiles
* @return {startNodeTask}
*/
export default function startNodeTaskFactory(
Expand All @@ -30,7 +31,19 @@ export default function startNodeTaskFactory(
getConnectionHost,
ensureFileMountExists,
homeDir,
getConfigProfiles,
) {
function getPlatformProfiles(config) {
const platformProfiles = getConfigProfiles(config)
.filter((profile) => profile.startsWith('platform'));

if (platformProfiles.length === 0) {
platformProfiles.push('platform');
}

return Array.from(new Set(platformProfiles));
}
Comment on lines +36 to +45
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Fix const mutation error.

platformProfiles is declared as const but is mutated on line 41 with .push(). This will cause a runtime error when no platform profiles exist.

Apply this diff to fix the issue:

-  function getPlatformProfiles(config) {
-    const platformProfiles = getConfigProfiles(config)
-      .filter((profile) => profile.startsWith('platform'));
+  function getPlatformProfiles(config) {
+    let platformProfiles = getConfigProfiles(config)
+      .filter((profile) => profile.startsWith('platform'));
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function getPlatformProfiles(config) {
const platformProfiles = getConfigProfiles(config)
.filter((profile) => profile.startsWith('platform'));
if (platformProfiles.length === 0) {
platformProfiles.push('platform');
}
return Array.from(new Set(platformProfiles));
}
function getPlatformProfiles(config) {
let platformProfiles = getConfigProfiles(config)
.filter((profile) => profile.startsWith('platform'));
if (platformProfiles.length === 0) {
platformProfiles.push('platform');
}
return Array.from(new Set(platformProfiles));
}
🤖 Prompt for AI Agents
In packages/dashmate/src/listr/tasks/startNodeTaskFactory.js around lines 36 to
45, platformProfiles is declared as const but mutated with .push(), causing an
error; change the declaration to let (or create a new array when adding the
default) so it can be mutated — e.g., declare let platformProfiles =
getConfigProfiles(config).filter(...); then if length is 0 push 'platform', and
return Array.from(new Set(platformProfiles)).


/**
* @typedef {startNodeTask}
* @param {Config} config
Expand Down Expand Up @@ -89,10 +102,7 @@ export default function startNodeTaskFactory(
title: 'Check node is not started',
enabled: (ctx) => !ctx.isForce,
task: async (ctx) => {
const profiles = [];
if (ctx.platformOnly) {
profiles.push('platform');
}
const profiles = ctx.platformOnly ? getPlatformProfiles(config) : [];

if (await dockerCompose.isNodeRunning(config, { profiles })) {
throw new Error('Running services detected. Please ensure all services are stopped for this config before starting');
Expand Down Expand Up @@ -147,10 +157,7 @@ export default function startNodeTaskFactory(
config.get('core.masternode.operator.privateKey', true);
}

const profiles = [];
if (ctx.platformOnly) {
profiles.push('platform');
}
const profiles = ctx.platformOnly ? getPlatformProfiles(config) : [];

await dockerCompose.up(config, { profiles });
},
Expand Down
24 changes: 16 additions & 8 deletions packages/dashmate/src/listr/tasks/stopNodeTaskFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,26 @@ import waitForDKGWindowPass from '../../core/quorum/waitForDKGWindowPass.js';
* @param {DockerCompose} dockerCompose
* @param {createRpcClient} createRpcClient
* @param {getConnectionHost} getConnectionHost
* @param {getConfigProfiles} getConfigProfiles
* @return {stopNodeTask}
*/
export default function stopNodeTaskFactory(
dockerCompose,
createRpcClient,
getConnectionHost,
getConfigProfiles,
) {
function getPlatformProfiles(config) {
const platformProfiles = getConfigProfiles(config)
.filter((profile) => profile.startsWith('platform'));

if (platformProfiles.length === 0) {
platformProfiles.push('platform');
}

return Array.from(new Set(platformProfiles));
}

/**
* Stop node
* @typedef stopNodeTask
Expand All @@ -27,10 +40,7 @@ export default function stopNodeTaskFactory(
title: 'Check node is running',
skip: (ctx) => ctx.isForce,
task: async (ctx) => {
const profiles = [];
if (ctx.platformOnly) {
profiles.push('platform');
}
const profiles = ctx.platformOnly ? getPlatformProfiles(config) : [];

if (!await dockerCompose.isNodeRunning(config, { profiles })) {
throw new Error('Node is not running');
Expand Down Expand Up @@ -70,10 +80,8 @@ export default function stopNodeTaskFactory(
{
title: `Stopping ${config.getName()} node`,
task: async (ctx) => {
const profiles = [];
if (ctx.platformOnly) {
profiles.push('platform');
}
const profiles = ctx.platformOnly ? getPlatformProfiles(config) : [];

await dockerCompose.stop(config, { profiles });
},
},
Expand Down
Loading