Skip to content

(fix) O3-902: Improve error message clarity and consistency in error handling#1725

Open
Safa-khanum wants to merge 1 commit intoopenmrs:mainfrom
Safa-khanum:fix/improve-error-messages
Open

(fix) O3-902: Improve error message clarity and consistency in error handling#1725
Safa-khanum wants to merge 1 commit intoopenmrs:mainfrom
Safa-khanum:fix/improve-error-messages

Conversation

@Safa-khanum
Copy link
Copy Markdown

Requirements

  • This PR has a title that briefly describes the work done including the ticket number.

If applicable

  • My work is based on designs, which are linked or shown either in the Jira ticket or the description below.
  • My work includes tests or is validated by existing tests.
  • I have updated the esm-framework and storybook mocks to reflect any API changes.

Summary

This PR improves error message clarity and consistency in the global error handling module.

Previously, non-Error inputs produced inconsistent and less descriptive messages. This change standardizes error formatting and provides clearer context for debugging.

Changes

  • Improved error messages for null and undefined values
  • Standardized formatting for object-based errors
  • Enhanced readability and developer debugging experience

Why this matters

Clear and consistent error messages improve debugging and developer experience, especially when handling unexpected inputs.

Screenshots

N/A

Related Issue

Inspired by #902

Other

Non-breaking internal improvement.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 31, 2026

⚠️ No Changeset found

Latest commit: f4924f1

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown
Member

@ibacher ibacher left a comment

Choose a reason for hiding this comment

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

First, please do not make up a ticket number. These references need to be valid and we do not use PR numbers as ticket numbers. Second, I don't really see the value in changing the messages here. Third, while it's a good idea to handle new cases, it's not at all clear why you switched from the else if structure that existed and prevented redundant comparisons. Fourth, I don't really see a lot of value in just pre-pending the string "Error:" to things.

Comment on lines -84 to +92
} else if (thing === null) {
return Error(`'null' was thrown as an error`);
} else if (typeof thing === 'object') {
}

if (thing === null) {
return new Error(`Received null instead of a valid error object.`);
}

if (thing === undefined) {
return new Error(`Received undefined instead of a valid error object.`);
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why did you change this from an else if? Also, these two branches feel like they could be combined.

}
}

// string / number / boolean
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's better to avoid comments of ovious code

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.

3 participants