Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restructure JavaScript exceptions #2562

Merged
merged 1 commit into from
Jul 25, 2024
Merged

Conversation

pepone
Copy link
Member

@pepone pepone commented Jul 24, 2024

  • Exceptions.js the base exception class
  • LocalException.js the LocalException base class
  • LocalExceptions.js all local exception derived type
  • UserException.js the user exception base class

Also update the UserException constructor to not take a cause argument, as per #2527

@pepone pepone requested review from externl and bernardnormier July 24, 2024 19:03
export class UserException extends Exception {
constructor() {
super();
Exception.captureStackTrace(this);
Copy link
Member Author

Choose a reason for hiding this comment

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

We can probably remove this, not sure why we were capturing stack traces for user exceptions

Copy link
Member

Choose a reason for hiding this comment

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

We shoud remove it. Can we then remove the constructor entirely?

@pepone
Copy link
Member Author

pepone commented Jul 24, 2024

The only relevant change is the updated UserException, constructor. The rest is to move classes around and update the import paths.

Copy link
Member

@bernardnormier bernardnormier left a comment

Choose a reason for hiding this comment

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

I assume the actual refactoring of the local exceptions is for a follow-up PR?

export class UserException extends Exception {
constructor() {
super();
Exception.captureStackTrace(this);
Copy link
Member

Choose a reason for hiding this comment

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

We shoud remove it. Can we then remove the constructor entirely?

* This exception is raised when a failure occurs during initialization.
**/
export class InitializationException extends LocalException {
constructor(reason = "", _cause = "") {
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand why the reason is defaulted to "". We should also provide a reason when we construct an InitializationException.

Is it possible to make a class as final/sealed in JS? If yes, then, we should use it in this file.

Copy link
Member Author

Choose a reason for hiding this comment

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

I will cleanup in a follow-up PR

* user exception factory more than once for the same ID.
**/
export class AlreadyRegisteredException extends LocalException {
constructor(kindOfObject = "", id = "", _cause = "") {
Copy link
Member

Choose a reason for hiding this comment

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

Same here, kindOfObject and id must always be provided by the caller.

@@ -38,7 +38,7 @@ const toString = function (key, object, objectTable, ident) {
//
// Ice.Exception
//
class Exception extends Error {
export class Exception extends Error {
Copy link
Member

Choose a reason for hiding this comment

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

We should use/fill Error.cause and Error.message, and definitely not define our own ice_cause property.

@pepone pepone merged commit 8a8a93e into zeroc-ice:main Jul 25, 2024
18 checks passed
InsertCreativityHere pushed a commit to InsertCreativityHere/compiler-comparison that referenced this pull request Jan 1, 2025
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.

2 participants