Skip to content

Conversation

@ricellis
Copy link
Member

@ricellis ricellis commented Nov 6, 2025

Checklist
  • npm test passes (tip: npm run lint-fix can correct most style issues)
  • tests are included
  • documentation is changed or added

Received a user report where a client-side disconnection results in:

TypeError: Cannot read properties of undefined (reading 'errors')
at parseServiceErrorMessage (node_modules\ibm-cloud-sdk-core\lib\request-wrapper.js:630:32)
at RequestWrapper.formatError (node_modules\ibm-cloud-sdk-core\lib\request-wrapper.js:391:29)
at node_modules\ibm-cloud-sdk-core\lib\request-wrapper.js:364:45
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

I haven't been able to reproduce a client-side disconnection that results in an axios error that includes a response at

if (axiosError.response) {

but doesn't have data at
error.message = parseServiceErrorMessage(axiosError.data) || axiosError.statusText;

Nonetheless

function parseServiceErrorMessage(response: any): string | undefined {

(Note that response here is response.data from the formatError function)
since parseServiceErrorMessage declares response: any, but does not check for undefined or null (which are permitted by any) before trying to access properties.

This PR adds a guard clause to prevent accessing properties in the event the passed response.data -> response was not defined to avoid the TypeError.

I added a test that fails before the change and passes after it validating that an error object without response.data does not throw.

Note: the build failures appear unrelated to this change, but rather an issue with a missing dependency. this worked on a re-run

@CLAassistant
Copy link

CLAassistant commented Nov 6, 2025

CLA assistant check
All committers have signed the CLA.

@pyrooka pyrooka self-requested a review November 11, 2025 10:02
Copy link
Member

@pyrooka pyrooka left a comment

Choose a reason for hiding this comment

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

Thanks a lot for adding the extra check to handle such cases! The new unit test case is also appreciated. Changes are looking good.

@pyrooka pyrooka merged commit 3001a0f into main Nov 11, 2025
14 of 17 checks passed
@pyrooka pyrooka deleted the handle-undefined-response-message-parse branch November 11, 2025 10:08
ibm-devx-sdk pushed a commit that referenced this pull request Nov 11, 2025
## [5.4.4](v5.4.3...v5.4.4) (2025-11-11)

### Bug Fixes

* check data is present before reading errors ([#309](#309)) ([3001a0f](3001a0f))
@ibm-devx-sdk
Copy link

🎉 This PR is included in version 5.4.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants