Skip to content
Merged
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
91 changes: 53 additions & 38 deletions src/util/logs-polling-utilities.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import EventEmitter from 'events';
import { createRequire } from 'module';
import { cliux } from '@contentstack/cli-utilities';
import { ApolloClient, ObservableQuery } from '@apollo/client/core';
import { Ora } from 'ora';
Expand All @@ -8,6 +9,8 @@ import { deploymentQuery, deploymentLogsQuery, serverlessLogsQuery } from '../gr
import { setTimeout as sleep } from 'timers/promises';
import { isNotDevelopment } from './apollo-client';

const requireApolloDeprecation = createRequire(__filename);

export default class LogPolling {
private config: ConfigType;
private $event!: EventEmitter;
Expand All @@ -33,19 +36,25 @@ export default class LogPolling {
* only during its execution, and restored immediately after.
*/
private withDeprecationsDisabled<T>(fn: () => T): T {

if (!isNotDevelopment) {
return fn();
}
let withDisabledDeprecations: any;

let withDisabledDeprecations: unknown;
try {
withDisabledDeprecations = require('@apollo/client/utilities/deprecation').withDisabledDeprecations;
withDisabledDeprecations = requireApolloDeprecation(
'@apollo/client/utilities/deprecation',
).withDisabledDeprecations;
} catch {
return fn();
}

const handler = withDisabledDeprecations();
if (typeof withDisabledDeprecations !== 'function') {
return fn();
}

const handler = (withDisabledDeprecations as () => unknown)();
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

The new guard that falls back when withDisabledDeprecations is missing or not a function is the core of this fix, but it isn’t covered by tests. Please add a regression test that simulates the module exporting a non-function (or missing) withDisabledDeprecations and asserts withDeprecationsDisabled still runs fn() without throwing.

Suggested change
const handler = (withDisabledDeprecations as () => unknown)();
let handler: unknown;
try {
handler = (withDisabledDeprecations as () => unknown)();
} catch {
// If setting up the deprecation handler fails, fall back to running fn without it.
return fn();
}

Copilot uses AI. Check for mistakes.

try {
return fn();
} finally {
Expand All @@ -61,14 +70,18 @@ export default class LogPolling {
dispose.call(handler);
return;
}
} catch {}
} catch {
void 0;
}
Comment on lines +73 to +75
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

void 0; in this catch block will likely trip ESLint's no-unused-expressions (enabled via eslint:recommended) and fails linting. Prefer an empty catch {} (if allowed) or add a comment / explicit handling instead of a no-op expression statement.

Copilot uses AI. Check for mistakes.
try {
const asyncDispose = (handler as any)[(Symbol as any).asyncDispose];
if (typeof asyncDispose === 'function') {
asyncDispose.call(handler);
return;
}
} catch {}
} catch {
void 0;
}
Comment on lines +82 to +84
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

Same as above: void 0; inside catch is an unused expression and is likely to fail no-unused-expressions. Use an empty catch or a comment / minimal handling instead.

Copilot uses AI. Check for mistakes.
try {
const symbols = Object.getOwnPropertySymbols(handler);
for (const sym of symbols) {
Expand All @@ -78,7 +91,9 @@ export default class LogPolling {
break;
}
}
} catch {}
} catch {
void 0;
}
Comment on lines +94 to +96
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

Same issue here: void 0; is a no-op expression statement and may be flagged by no-unused-expressions. Prefer catch {} (or a short comment) to intentionally swallow the error.

Copilot uses AI. Check for mistakes.
}

/**
Expand All @@ -101,17 +116,17 @@ export default class LogPolling {
> {
return this.withDeprecationsDisabled(() => {
const statusWatchQuery = this.apolloManageClient.watchQuery({
fetchPolicy: 'network-only',
query: deploymentQuery,
variables: {
query: {
uid: this.config.deployment,
environment: this.config.environment,
fetchPolicy: 'network-only',
query: deploymentQuery,
variables: {
query: {
uid: this.config.deployment,
environment: this.config.environment,
},
},
},
pollInterval: this.config.pollingInterval,
errorPolicy: 'all',
});
pollInterval: this.config.pollingInterval,
errorPolicy: 'all',
});
return statusWatchQuery;
});
}
Expand Down Expand Up @@ -146,14 +161,14 @@ export default class LogPolling {
});
const logsWatchQuery = this.withDeprecationsDisabled(() => {
return this.apolloLogsClient.watchQuery({
fetchPolicy: 'network-only',
query: deploymentLogsQuery,
variables: {
deploymentUid: this.config.deployment,
},
pollInterval: this.config.pollingInterval,
errorPolicy: 'all',
});
fetchPolicy: 'network-only',
query: deploymentLogsQuery,
variables: {
deploymentUid: this.config.deployment,
},
pollInterval: this.config.pollingInterval,
errorPolicy: 'all',
});
});
this.subscribeDeploymentLogs(logsWatchQuery);
}
Expand Down Expand Up @@ -243,19 +258,19 @@ export default class LogPolling {

const serverLogsWatchQuery = this.withDeprecationsDisabled(() => {
return this.apolloLogsClient.watchQuery({
fetchPolicy: 'network-only',
query: serverlessLogsQuery,
variables: {
query: {
environmentUid: this.config.environment,
startTime: this.startTime,
endTime: this.endTime,
deploymentUid: this.config.deployment,
fetchPolicy: 'network-only',
query: serverlessLogsQuery,
variables: {
query: {
environmentUid: this.config.environment,
startTime: this.startTime,
endTime: this.endTime,
deploymentUid: this.config.deployment,
},
},
},
pollInterval: this.config.pollingInterval,
errorPolicy: 'all',
});
pollInterval: this.config.pollingInterval,
errorPolicy: 'all',
});
});
this.subscribeServerLogs(serverLogsWatchQuery);
}
Expand Down
Loading