-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chain, node: catch critical errors and shut down
- Loading branch information
Showing
6 changed files
with
108 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/*! | ||
* errors.js - internal error objects for hsd | ||
* Copyright (c) 2022 The Handshake Developers (MIT License). | ||
* https://github.com/handshake-org/hsd | ||
*/ | ||
|
||
'use strict'; | ||
|
||
/** | ||
* @module errors | ||
*/ | ||
|
||
const assert = require('bsert'); | ||
|
||
/** | ||
* Critical Error | ||
* An error severe enough to warrant shutting down the node. | ||
* @extends Error | ||
* @param {Block|TX} msg | ||
* @param {String} code - Reject packet code. | ||
* @param {String} reason - Reject packet reason. | ||
* @param {Number} score - Ban score increase | ||
* (can be -1 for no reject packet). | ||
* @param {Boolean} malleated | ||
*/ | ||
|
||
class CriticalError extends Error { | ||
/** | ||
* Create a verify error. | ||
* @constructor | ||
* @param {Block|TX} msg | ||
* @param {String} code - Reject packet code. | ||
* @param {String} reason - Reject packet reason. | ||
* @param {Number} score - Ban score increase | ||
* (can be -1 for no reject packet). | ||
* @param {Boolean} malleated | ||
*/ | ||
|
||
constructor(err) { | ||
super(); | ||
|
||
this.type = 'CriticalError'; | ||
|
||
if (err instanceof Error) { | ||
this.message = `Critical Error: ${err.message}`; | ||
} else { | ||
assert(typeof err === 'string'); | ||
this.message = `Critical Error: ${err}`; | ||
} | ||
|
||
if (Error.captureStackTrace) | ||
Error.captureStackTrace(this, CriticalError); | ||
} | ||
} | ||
|
||
/* | ||
* Expose | ||
*/ | ||
|
||
exports.CriticalError = CriticalError; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters