Skip to content

Conversation

@MaximeBajeux
Copy link
Contributor

ref: #MANAGER-EU-188KC

Description

Ticket Reference: #...

Additional Information

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses Sentry issues by adding defensive null/undefined checks throughout the codebase. The changes primarily involve adding optional chaining operators to prevent runtime errors when accessing properties or methods on potentially null/undefined values.

Changes:

  • Added optional chaining operators to various method calls and property accesses to prevent null/undefined errors
  • Improved DOM manipulation safety by using .remove() instead of removeChild() and adding parent node validation
  • Enhanced error handling with optional chaining on error response objects

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
packages/manager/modules/manager-components/src/changelog-button/controller.js Added optional chaining to chapters array reduce operation
packages/manager/modules/core/src/url-builder/url-builder.provider.js Added optional chaining to Object.keys().reduce() call
packages/manager/core/url-builder/src/url-builder.ts Added optional chaining to string operations and updated formatting
packages/manager/core/api/src/iceberg.ts Added optional chaining to route.includes() check
packages/manager/apps/procedures/src/utils/iframe.ts Enhanced iframe removal safety with parent node validation
packages/components/ovh-shell/src/plugin/ux/components/modal.ts Replaced removeChild() with safer remove() method
packages/components/ovh-payment-method/src/ovh-payment-method.js Added optional chaining to error response status checks

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 12 to 18
this.computedTrackingContext = this.chapters?.reduce(
(acc, value, index) => {
acc[chapterKeys[index]] = value;
return acc;
},
{},
);
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

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

If this.chapters is null or undefined, this.computedTrackingContext will also be undefined. This will cause an error on line 28 where it's spread into an object using the spread operator. Consider providing a fallback value such as an empty object to ensure the spread operation doesn't fail.

Suggested change
this.computedTrackingContext = this.chapters?.reduce(
(acc, value, index) => {
acc[chapterKeys[index]] = value;
return acc;
},
{},
);
this.computedTrackingContext =
(this.chapters?.reduce(
(acc, value, index) => {
acc[chapterKeys[index]] = value;
return acc;
},
{},
)) ?? {};

Copilot uses AI. Check for mistakes.

return buildURLs(
Object.keys(routes).reduce((all, name) => {
Object.keys(routes)?.reduce((all, name) => {
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

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

The optional chaining operator is unnecessary here. Object.keys() always returns an array (possibly empty) when given an object, so it will never return null or undefined. The optional chaining suggests a misunderstanding of the API and adds unnecessary code. If routes itself could be null/undefined, the check should be on routes, not on Object.keys(routes).

Suggested change
Object.keys(routes)?.reduce((all, name) => {
Object.keys(routes).reduce((all, name) => {

Copilot uses AI. Check for mistakes.
let filteredParams = params;

if (pattern.includes(':') && params) {
if (pattern?.includes(':') && params) {
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

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

The parameter pattern is typed as string (non-nullable), but optional chaining is used here. This is inconsistent - either the type should allow null/undefined values (e.g., string | null | undefined), or the optional chaining should be removed. If the intention is to handle nullable values, the function signature should be updated to reflect this.

Suggested change
if (pattern?.includes(':') && params) {
if (pattern.includes(':') && params) {

Copilot uses AI. Check for mistakes.
Comment on lines 61 to 64
if (baseURL?.includes('#') && buildedPath?.includes('#')) {
buildedPath = buildedPath.replace('#', '');
}
if (baseURL.endsWith('/') && buildedPath.startsWith('/')) {
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

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

Inconsistent use of optional chaining on the baseURL parameter. Line 61 uses baseURL?.includes('#') with optional chaining, but line 64 uses baseURL.endsWith('/') without it. Since baseURL is typed as a non-nullable string, either both should use optional chaining (and the type should be updated), or neither should. This inconsistency suggests incomplete defensive coding.

Copilot uses AI. Check for mistakes.
let queryString = queryObject ? buildQueryString(queryObject) : '';
if (queryString) {
queryString = buildedPath.includes('?') ? `&${queryString}` : `?${queryString}`;
queryString = buildedPath?.includes('?')
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

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

The parameter buildedPath is derived from urlPattern.url and is guaranteed to be a string at this point. Using optional chaining here is unnecessary and suggests the code may not be handling null/undefined values correctly upstream. If buildedPath could be null/undefined, this should be addressed where it's assigned rather than using optional chaining here.

Copilot uses AI. Check for mistakes.
.setIamTags(
params,
filters,
route?.includes('/iam/resource') ? 'tags' : 'iamTags',
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

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

The parameter route is a required string parameter in the function signature. Using optional chaining here suggests that route could be null or undefined, which contradicts the type signature. If nullable values are expected, the type should be updated to string | null | undefined. Otherwise, the optional chaining is unnecessary and masks potential bugs where null/undefined values are incorrectly passed.

Suggested change
route?.includes('/iam/resource') ? 'tags' : 'iamTags',
route.includes('/iam/resource') ? 'tags' : 'iamTags',

Copilot uses AI. Check for mistakes.
Copilot AI review requested due to automatic review settings January 21, 2026 09:53
@MaximeBajeux MaximeBajeux force-pushed the fix/sentry-issues-common branch from 3598fa7 to a3bbfaf Compare January 21, 2026 09:53
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 8 to 11
const buildURLPattern = (
pattern: string,
params: Record<string, ParamValueType>,
) => {
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

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

The function signature declares pattern and params as non-nullable, but optional chaining is used on pattern at line 15. This creates a type contract inconsistency. If pattern can be null or undefined at runtime (as suggested by the defensive optional chaining), the function signature should be updated to reflect this: pattern?: string | null, params?: Record<string, ParamValueType>.

Copilot uses AI. Check for mistakes.
const { params: queryObject } = urlPattern;

if (baseURL.includes('#') && buildedPath.includes('#')) {
if (baseURL?.includes('#') && buildedPath?.includes('#')) {
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

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

The buildURL function signature (outside the diff) declares baseURL and path as non-nullable strings, but optional chaining is used here when calling includes() on them. This creates a type contract inconsistency. If these parameters can be null or undefined at runtime (as suggested by the defensive optional chaining), the function signature should be updated to allow nullable types.

Copilot uses AI. Check for mistakes.
@MaximeBajeux MaximeBajeux force-pushed the fix/sentry-issues-common branch from a3bbfaf to 7dc1d98 Compare January 21, 2026 13:16
Copilot AI review requested due to automatic review settings January 21, 2026 13:24
@MaximeBajeux MaximeBajeux force-pushed the fix/sentry-issues-common branch from 7dc1d98 to 596f0c7 Compare January 21, 2026 13:24
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +87 to 88
this.elements.body.firstElementChild?.remove();
this.elements.body.append(this.options.content);
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

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

The optional chaining is applied to firstElementChild but not to this.elements.body itself. Since IModalElements defines body as optional (body?: HTMLElement), accessing this.elements.body.firstElementChild could throw an error if body is undefined. The same issue exists on line 88 with this.elements.body.append(). Both lines should use optional chaining for body as well: this.elements.body?.firstElementChild?.remove() and this.elements.body?.append(this.options.content).

Copilot uses AI. Check for mistakes.
anooparveti
anooparveti previously approved these changes Jan 21, 2026
ref: #MANAGER-EU-188KC

Signed-off-by: Maxime Bajeux <maxime.bajeux.ext@ovhcloud.com>
Co-authored-by: Dustin Kroger <dustin.kroger.ext@ovhcloud.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working common container

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants