PrismarineJS / flying-squid

Create Minecraft servers with a powerful, stable, and high level JavaScript API.
https://prismarinejs.github.io/flying-squid/
MIT License
547 stars 100 forks source link

Make server don't crash from non fatal errors. #612

Open nathan130200 opened 2 years ago

nathan130200 commented 2 years ago

I was testing sample server code. And i just had tried use /attach command with an entity selector, and server crashed

\flying-squid\src\lib\plugins\commands.js:11
     else setTimeout(() => { throw err }, 0)
                              ^

TypeError: Cannot read properties of null (reading '1')
    at serv.selectorString (C:\Users\Nathan\Documents\Minecraft\Servers\basic-server-node\node_modules\flying-squid\src\lib\plugins\commands.js:282:14)
    at entity.selectorString (C:\Users\Nathan\Documents\Minecraft\Servers\basic-server-node\node_modules\flying-squid\src\lib\plugins\commands.js:17:41)
    at parse (C:\Users\Nathan\Documents\Minecraft\Servers\basic-server-node\node_modules\flying-squid\src\lib\plugins\spawn.js:184:48)       
    at Command.use (C:\Users\Nathan\Documents\Minecraft\Servers\basic-server-node\node_modules\flying-squid\src\lib\command.js:35:28)        
    at player.handleCommand (C:\Users\Nathan\Documents\Minecraft\Servers\basic-server-node\node_modules\flying-squid\src\lib\plugins\commands.js:7:39)
    at C:\Users\Nathan\Documents\Minecraft\Servers\basic-server-node\node_modules\flying-squid\src\lib\plugins\chat.js:125:89
    at Entity.behavior (C:\Users\Nathan\Documents\Minecraft\Servers\basic-server-node\node_modules\flying-squid\src\lib\behavior.js:24:14)   
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v18.10.0

Instead propagate entire error, why just forward to error and clientError events as described in docs

UPDATE: I had to set unhandled exception hook in nodejs to don't close server:

process.setUncaughtExceptionCaptureCallback(err => {
    console.log('UNHANDLED ERROR: ' + err);
});

Log


October 9th 2022, 17:25:33 [INFO]: FRNathan13 issued command: /attach
UNHANDLED ERROR: TypeError: Cannot read properties of null (reading '1')```