Skip to content

chore: Fix error code mapping#1571

Merged
lantoli merged 3 commits intomasterfrom
CLOUDP-380707_error_code_map
Feb 12, 2026
Merged

chore: Fix error code mapping#1571
lantoli merged 3 commits intomasterfrom
CLOUDP-380707_error_code_map

Conversation

@lantoli
Copy link
Copy Markdown
Member

@lantoli lantoli commented Feb 12, 2026

Proposed changes

Fix error code mapping to address HELP-88769. Note that this affects all CFN resources, not only cluster. Cluster E2E testings are passing, link.

CFN stack was being deleted successfully incorrectly for a cluster with termination protection because:

  • While deleting in progress, if NotFound error is returned, CFN assumes it's already deleted and that's ok
  • CANNOT_TERMINATE_CLUSTER_WHEN_TERMINATION_PROTECTION_ENABLED Atlas error is 400 Bad request and is mapped incorrectly to NotFound

Jira ticket: CLOUDP-380707

Type of change:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as
    expected)
  • This change requires a documentation update
  • If changes include removal or addition of 3rd party GitHub actions, I updated our internal document. Reach out to the APIx Integration slack channel to get access to the internal document.

Manual QA performed:

  • cfn invoke for each of CRUDL/cfn test
  • Updated resource in example
  • Published to AWS private registry
  • Used the template in example to create and update a stack in AWS
  • Deleted stack to ensure resources are deleted
  • Created multiple resources in same stack
  • Validated in Atlas UI
  • Included screenshots

Required Checklist:

  • I have signed the MongoDB CLA
  • I have added tests that prove my fix is effective or that my feature works
  • I have checked that this change does not generate any credentials and that they are NOT accidentally logged anywhere.
  • I have added any necessary documentation (if appropriate)
  • I have run make fmt and formatted my code
  • For CFN Resources: I have released by changes in the private registry and proved by change
    works in Atlas

Further comments

Before (CFN stack deleted incorrectly):

delete1

In this PR (CFN stack deletion fails):

delete2

return handler.ProgressEvent{
OperationStatus: handler.Failed,
Message: message,
HandlerErrorCode: string(types.HandlerErrorCodeNotFound)}
Copy link
Copy Markdown
Member Author

@lantoli lantoli Feb 12, 2026

Choose a reason for hiding this comment

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

wrong mapping, and already handled in getHandlerErrorCode

if resp != nil && resp.StatusCode == http.StatusBadRequest && strings.Contains(err.Error(), constants.Duplicate) {
pe.HandlerErrorCode = string(types.HandlerErrorCodeAlreadyExists)
}
if resp != nil && resp.StatusCode == http.StatusNotFound {
Copy link
Copy Markdown
Member Author

@lantoli lantoli Feb 12, 2026

Choose a reason for hiding this comment

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

redundant as it's already done in GetFailedEventByResponse at the beginning of the func

}

if response.StatusCode == http.StatusUnauthorized {
return handler.ProgressEvent{
Copy link
Copy Markdown
Member Author

@lantoli lantoli Feb 12, 2026

Choose a reason for hiding this comment

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

wrong mapping, and already handled in getHandlerErrorCode

return string(types.HandlerErrorCodeInvalidRequest)
case http.StatusNotFound:
return string(types.HandlerErrorCodeNotFound)
case http.StatusConflict:
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

moved logic from GetFailedEventByResponse for StatusConflict

@lantoli lantoli marked this pull request as ready for review February 12, 2026 07:28
@lantoli lantoli requested a review from a team as a code owner February 12, 2026 07:28
Copilot AI review requested due to automatic review settings February 12, 2026 07:28
Copy link
Copy Markdown
Contributor

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 fixes incorrect HTTP status code to CloudFormation error code mappings that caused stacks to be deleted incorrectly when clusters had termination protection enabled. The fix consolidates error mapping logic into a single function and removes duplicate/incorrect mappings.

Changes:

  • Consolidated HTTP status code to error code mapping logic into getHandlerErrorCode function
  • Removed duplicate error handling code that incorrectly mapped BadRequest and Unauthorized to NotFound
  • Removed redundant NotFound status code check in cluster error handling

Reviewed changes

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

File Description
cfn-resources/util/progressevent/failed_event.go Consolidated error code mapping logic into getHandlerErrorCode and removed duplicate mapping code from GetFailedEventByResponse
cfn-resources/util/cluster_common.go Removed redundant NotFound status code check that duplicated logic now in getHandlerErrorCode

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

Copy link
Copy Markdown
Collaborator

@manupedrozo manupedrozo left a comment

Choose a reason for hiding this comment

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

Nice find

Copy link
Copy Markdown
Member

@AgustinBettati AgustinBettati left a comment

Choose a reason for hiding this comment

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

Nice refactor

Copy link
Copy Markdown
Collaborator

@marcosuma marcosuma left a comment

Choose a reason for hiding this comment

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

How should we interpret this? it seems a bug fix so ok to minor version I guess?

@lantoli
Copy link
Copy Markdown
Member Author

lantoli commented Feb 12, 2026

How should we interpret this? it seems a bug fix so ok to minor version I guess?

@marcosuma yes, it's a bug in the error type we return in some situations

@lantoli lantoli added this pull request to the merge queue Feb 12, 2026
Merged via the queue into master with commit 43f5492 Feb 12, 2026
50 checks passed
@lantoli lantoli deleted the CLOUDP-380707_error_code_map branch February 12, 2026 11:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants