Skip to content

Commit df12f8e

Browse files
Merge pull request #4018 from OriginTrail/improvment/better-error-handling
Improvment/better error handling
2 parents 55605b6 + 9c98a19 commit df12f8e

File tree

3 files changed

+63
-3
lines changed

3 files changed

+63
-3
lines changed

index.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,72 @@ process.on('unhandledRejection', (err) => {
5757
return; // Don't crash for peer lookup failures
5858
}
5959

60+
// Handle ECONNRESET errors gracefully - these are common network issues
61+
if (err && (err.code === 'ECONNRESET' || err.errno === -104)) {
62+
console.warn(`Network connection reset (ECONNRESET): ${err.message}`);
63+
return; // Don't crash for connection reset errors
64+
}
65+
66+
// Handle ERR_UNSUPPORTED_PROTOCOL errors gracefully
67+
if (err && err.code === 'ERR_UNSUPPORTED_PROTOCOL') {
68+
console.warn(`Unsupported protocol error (ERR_UNSUPPORTED_PROTOCOL): ${err.message}`);
69+
return; // Don't crash for protocol errors
70+
}
71+
72+
// Handle EPIPE (broken pipe) errors gracefully
73+
if (err && (err.code === 'EPIPE' || err.errno === -32)) {
74+
console.warn(`Broken pipe error (EPIPE): ${err.message}`);
75+
return; // Don't crash for broken pipe errors
76+
}
77+
78+
// Handle ETIMEDOUT errors gracefully - these are common database connection timeouts
79+
if (err && (err.code === 'ETIMEDOUT' || err.errno === -110)) {
80+
console.warn(`Connection timeout error (ETIMEDOUT): ${err.message}`);
81+
return; // Don't crash for timeout errors
82+
}
83+
84+
// Handle Sequelize "Got timeout reading communication packets" errors gracefully
85+
if (err && err.message && err.message.includes('Got timeout reading communication packets')) {
86+
console.warn(`Sequelize communication timeout error: ${err.message}`);
87+
return; // Don't crash for database communication timeout errors
88+
}
89+
6090
// For all other unhandled rejections, crash the node
6191
console.error('Something went really wrong! OT-node shutting down...', err);
6292
process.exit(1);
6393
});
6494

6595
process.on('uncaughtException', (err) => {
96+
// Handle ERR_UNSUPPORTED_PROTOCOL errors gracefully
97+
if (err && err.code === 'ERR_UNSUPPORTED_PROTOCOL') {
98+
console.warn(`Unsupported protocol error (ERR_UNSUPPORTED_PROTOCOL): ${err.message}`);
99+
return; // Don't crash for protocol errors
100+
}
101+
102+
// Handle EPIPE (broken pipe) errors gracefully
103+
if (err && (err.code === 'EPIPE' || err.errno === -32)) {
104+
console.warn(`Broken pipe error (EPIPE): ${err.message}`);
105+
return; // Don't crash for broken pipe errors
106+
}
107+
108+
// Handle ECONNRESET errors gracefully
109+
if (err && (err.code === 'ECONNRESET' || err.errno === -104)) {
110+
console.warn(`Network connection reset (ECONNRESET): ${err.message}`);
111+
return; // Don't crash for connection reset errors
112+
}
113+
114+
// Handle ETIMEDOUT errors gracefully - these are common database connection timeouts
115+
if (err && (err.code === 'ETIMEDOUT' || err.errno === -110)) {
116+
console.warn(`Connection timeout error (ETIMEDOUT): ${err.message}`);
117+
return; // Don't crash for timeout errors
118+
}
119+
120+
// Handle Sequelize "Got timeout reading communication packets" errors gracefully
121+
if (err && err.message && err.message.includes('Got timeout reading communication packets')) {
122+
console.warn(`Sequelize communication timeout error: ${err.message}`);
123+
return; // Don't crash for database communication timeout errors
124+
}
125+
66126
console.error('Something went really wrong! OT-node shutting down...', err);
67127
process.exit(1);
68128
});

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "origintrail_node",
3-
"version": "8.1.1-rc.8",
3+
"version": "8.1.1-rc.9",
44
"description": "OTNode V8",
55
"main": "index.js",
66
"type": "module",

0 commit comments

Comments
 (0)