From 6ee84c41bf392f2b128e198e66a72285e110fe92 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Sat, 24 Aug 2019 18:38:09 +0200 Subject: [PATCH 1/3] Add development branch notice Add notice to the top of README.md stating this is the development branch for 2.0 and that the 1.2.x branch should be used for production systems. --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 9522d40a..d2c04596 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,13 @@ Discord for development/support/play: https://discord.gg/5XuDkje +## Important notice + +This is the development branch for factorioClusterio 2.0 which is currently undergoing heavy +restructuring and refactoring. Expect plugins and existing installations to frequenltly break when +using this branch. If you don't want to be an alpha tester for 2.0 please use the stable +[1.2.x branch](https://github.com/clusterio/factorioClusterio/tree/1.2.x). + ### Ways to support me/the project: * Contribute with code/documentation. Always nice to move the project forward From 84f48e36f4e419e3cd8aec04d69008616e9fbe87 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Sun, 1 Sep 2019 16:07:31 +0200 Subject: [PATCH 2/3] Improve error reporting at startup Add StartupError that differentiates unhandled errors from errors with known causes and use it to only print the "please report" banner when an unhandled error occurs. Also makes the error reporting more visible in the console. --- master.js | 51 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 8 deletions(-) diff --git a/master.js b/master.js index 4af91d1e..bc63a58c 100644 --- a/master.js +++ b/master.js @@ -857,6 +857,29 @@ async function getPlugins(){ return plugins; } +// Errror class for known errors occuring during startup +class StartupError extends Error { } + +/** + * Calls listen on server capturing any errors that occurs + * binding to the port. + */ +function listen(server, ...args) { + return new Promise((resolve, reject) => { + function wrapError(err) { + reject(new StartupError( + `Server listening failed: ${err.message}` + )); + } + + server.once('error', wrapError); + server.listen(...args, () => { + server.off('error', wrapError); + resolve(); + }); + }); +} + async function startServer() { // Set the process title, shows up as the title of the CMD window on windows // and as the process name in ps/top on linux. @@ -921,7 +944,7 @@ async function startServer() { // Only start listening for connections after all plugins have loaded if (httpPort) { let httpServer = require("http").Server(app); - httpServer.listen(httpPort); + await listen(httpServer, httpPort); console.log("Listening for HTTP on port %s...", httpServer.address().port); } @@ -932,15 +955,16 @@ async function startServer() { privateKey = await fs.readFile(config.sslPrivKey); } catch (err) { - console.error(`Error loading ssl certificate: ${err.message}`); - await shutdown() + throw new StartupError( + `Error loading ssl certificate: ${err.message}` + ); } let httpsServer = require("https").createServer({ key: privateKey, cert: certificate }, app) - httpsServer.listen(httpsPort); + await listen(httpsServer, httpsPort); console.log("Listening for HTTPS on port %s...", httpsServer.address().port); } } @@ -949,10 +973,21 @@ module.exports = app; if (module === require.main) { startServer().catch(err => { - console.error( - "Unexpected error occured while starting master, please report\n"+ - "it to https://github.com/clusterio/factorioClusterio/issues" - ); + if (!(err instanceof StartupError)) { + console.error(` ++---------------------------------------------------------------+ +| Unexpected error occured while starting master, please report | +| it to https://github.com/clusterio/factorioClusterio/issues | ++---------------------------------------------------------------+` + ); + } else { + console.error(` ++----------------------------------+ +| Unable to to start master server | ++----------------------------------+` + ); + } + console.error(err); return shutdown(); }); From 703423ae54614d6727e1c541c496d628e720cdfb Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Sun, 1 Sep 2019 23:33:41 +0200 Subject: [PATCH 3/3] Add development branch warning at startup Add a big banner based warning telling this is the development branch for clusterio to the startup of client.js and master.js. --- client.js | 7 +++++++ master.js | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/client.js b/client.js index bb82a891..af750e09 100644 --- a/client.js +++ b/client.js @@ -20,6 +20,13 @@ const stringUtils = require("lib/stringUtils.js"); const configManager = require("lib/manager/configManager.js"); const hashFile = require('lib/hash').hashFile; +console.warn(` ++==========================================================+ +I WARNING: This is the development branch for the 2.0 I +I version of clusterio. Expect things to break. I ++==========================================================+ +`); + // argument parsing const args = require('minimist')(process.argv.slice(2)); diff --git a/master.js b/master.js index bc63a58c..dc68b2a4 100644 --- a/master.js +++ b/master.js @@ -972,6 +972,13 @@ async function startServer() { module.exports = app; if (module === require.main) { + console.warn(` ++==========================================================+ +I WARNING: This is the development branch for the 2.0 I +I version of clusterio. Expect things to break. I ++==========================================================+ +` + ); startServer().catch(err => { if (!(err instanceof StartupError)) { console.error(`