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

fix(getMessages): Emit Error object in "error" event #1387

Draft
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

frobinsonj
Copy link
Contributor

Didn't really know how to title this, apologies if I got it wrong.

Error event err param should be type Error - https://github.com/abalabahaha/eris/blob/dev/index.d.ts#L711

@DonovanDMC
Copy link
Contributor

It would probably be better to construct the error object, then overwrite the stack
Or even just override the message of the caught error then emit it rather than both making a new error object & emitting the original stack

lib/Client.js Outdated
@@ -2673,7 +2673,7 @@ class Client extends EventEmitter {
try {
return new Message(message, this);
} catch(err) {
this.emit("error", `Error creating message from channel messages\n${err.stack}\n${JSON.stringify(messages)}`);
this.emit("error", new Error(`Error creating message from channel messages\n${err.stack}\n${JSON.stringify(messages)}`));
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
this.emit("error", new Error(`Error creating message from channel messages\n${err.stack}\n${JSON.stringify(messages)}`));
err.message = `Error creating message from channel messages\n${JSON.stringify(messages)}`;
this.emit("error", err);

@DonovanDMC DonovanDMC changed the title fix(getMessages): Emit "error" with type Error fix(getMessages): Emit Error object in "error" event Jun 17, 2022
Copy link
Contributor

@DonovanDMC DonovanDMC left a comment

Choose a reason for hiding this comment

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

options.cause was added in node 16.9.0, we're currently on v10 (v14 at the latest), so we cannot use it

@DonovanDMC DonovanDMC added the bug label Jun 18, 2022
@frobinsonj
Copy link
Contributor Author

options.cause was added in node 16.9.0, we're currently on v10 (v14 at the latest), so we cannot use it

Went with your original suggestion. Thanks.

Copy link
Owner

@abalabahaha abalabahaha left a comment

Choose a reason for hiding this comment

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

Setting .message doesn't affect .stack. TBH I don't think the full JSON belongs in the error message. warn (also not great) and debug events are used to log JSON for other parsing errors

@DonovanDMC
Copy link
Contributor

DonovanDMC commented Jun 18, 2022

We can slice the first line off the stack and remake it with the new message

or we can just ignore the original stack and construct a new error

@abalabahaha abalabahaha added this to the 0.17.x milestone Jun 29, 2022
@bsian03
Copy link
Collaborator

bsian03 commented Jan 5, 2024

Any other alternatives to this? Current solution (although error might be hard to read) is the best one imo

@bsian03 bsian03 marked this pull request as draft January 9, 2024 22:09
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.

None yet

4 participants