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

Improve/error handling #143

Merged
merged 5 commits into from
Mar 14, 2024
Merged

Improve/error handling #143

merged 5 commits into from
Mar 14, 2024

Conversation

abdheshnayak
Copy link
Member

No description provided.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @abdheshnayak - I've reviewed your changes and they look great!

General suggestions:

  • Consider implementing an exponential backoff strategy for socket reconnections to improve robustness in unstable network conditions.
  • Review the use of ESLint rule disabling to ensure it doesn't hide potential issues, especially regarding naming conventions.
  • Ensure consistent error logging practices for better debugging and maintenance.
  • Address the typo in the function name to improve code clarity.
Here's what I looked at during the review
  • 🟡 General issues: 5 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Docstrings: all looks good

Thanks for using Sourcery. We offer it for free for open source projects and would be very grateful if you could help us grow. If you like it, would you consider sharing Sourcery on your favourite social media? ✨

Share Sourcery

Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

Comment on lines +229 to +264
const connnect = (recon = () => {}) => {
try {
sockPromise.current = new Promise<wsock.w3cwebsocket>(
(res, rej) => {
try {
// eslint-disable-next-line new-cap
const w = new wsock.w3cwebsocket(
`${socketUrl}/ws`,
'',
'',
{}
);

w.onmessage = onMessage;

w.onopen = () => {
res(w);
};

w.onerror = (e) => {
console.error(e);
recon();
};

w.onclose = () => {
recon();
};
} catch (e) {
rej(e);
}
};
}
);
} catch (e) {
logger.error(e);
}
};
Copy link

Choose a reason for hiding this comment

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

nitpick (typo): The function name 'connnect' seems to be a typo. Consider renaming it to 'connect' for clarity.

sockPromise.current = new Promise<wsock.w3cwebsocket>(
(res, rej) => {
try {
// eslint-disable-next-line new-cap
Copy link

Choose a reason for hiding this comment

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

suggestion (code_refinement): Disabling ESLint rules can hide potential issues. If the 'new-cap' rule is frequently disabled, consider configuring this rule project-wide or ensuring that the naming conventions for constructors are followed.

Comment on lines +248 to +250
w.onerror = (e) => {
console.error(e);
recon();
Copy link

Choose a reason for hiding this comment

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

suggestion (code_refinement): Logging the error before calling the reconnect function could provide valuable debugging information. Consider logging the error using logger.error or console.error before the recon() call.

Comment on lines +266 to +271
connnect(() => {
setTimeout(() => {
console.log('reconnecting');
connnect();
}, 1000);
});
Copy link

Choose a reason for hiding this comment

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

suggestion (performance): Implementing an exponential backoff strategy for reconnection attempts could improve the robustness of the socket connection, especially in unstable network conditions. Constantly reconnecting every 1 second might not be the most efficient approach.

@@ -747,7 +747,7 @@ const LogComp = ({
{isLoading && <LoadingComp />}

{errors.length ? (
<pre>{JSON.stringify(errors)}</pre>
<pre>{JSON.stringify(errors, null, 2)}</pre>
Copy link

Choose a reason for hiding this comment

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

suggestion (code_refinement): Formatting the errors with JSON.stringify(errors, null, 2) improves readability in the UI. This is a good practice for enhancing the debugging experience.

@abdheshnayak abdheshnayak merged commit 0ea18b1 into release-v1.0.5 Mar 14, 2024
4 checks passed
@abdheshnayak abdheshnayak deleted the improve/error-handling branch March 14, 2024 06:43
abdheshnayak added a commit that referenced this pull request Oct 28, 2024
* 🎨 Improved error handling for serverside
tulsiojha pushed a commit that referenced this pull request Nov 1, 2024
* 🎨 Improved error handling for serverside
abdheshnayak added a commit that referenced this pull request Nov 5, 2024
* 🎨 Improved error handling for serverside
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.

1 participant