Skip to content

Commit

Permalink
fix: handle other port already in use error message (#118)
Browse files Browse the repository at this point in the history
New error message '[datastore] Exiting due to exception: java.net.BindException: Address already in use'
  • Loading branch information
ert78gb authored Jun 22, 2022
1 parent a6ed5d3 commit 19bd174
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/base-emulator.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict';
const DEV_APP_SERVER_RUNNING_KEY = '[datastore] Dev App Server is now running.';
const DEV_APP_PORT_BIND_ERROR = '[datastore] Exiting due to exception: java.io.IOException: Failed to bind';

const EventEmitter = require('events');
const fse = require('fs-extra');

const EmulatorStates = require('./emulator-states');
const getConsistencyArg = require('./get-consistency-arg')
const isPortAlreadyInUse = require('./is-port-already-in-use')
class DataStoreStateEmitter extends EventEmitter {
}

Expand Down Expand Up @@ -105,7 +105,7 @@ class BaseEmulator {
if (text.indexOf(DEV_APP_SERVER_RUNNING_KEY) > -1) {
this._setEnviromentVariables();
this._setState(EmulatorStates.RUNNING);
} else if (text.includes(DEV_APP_PORT_BIND_ERROR)) {
} else if (isPortAlreadyInUse(text)) {
this._setState(EmulatorStates.ERROR, new Error(`"${this._options.host}:${this._options.port}" port already in use!`));
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/is-port-already-in-use.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const DEV_APP_PORT_BIND_ERRORS = [
'[datastore] Exiting due to exception: java.io.IOException: Failed to bind',
'[datastore] Exiting due to exception: java.net.BindException: Address already in use',
]

function isPortAlreadyInUse(text) {
return DEV_APP_PORT_BIND_ERRORS
.some(message => text.includes(message))
}

module.exports = isPortAlreadyInUse

0 comments on commit 19bd174

Please sign in to comment.