Skip to content

Commit

Permalink
refactor(server): Clearer error messages on fatal errors
Browse files Browse the repository at this point in the history
  • Loading branch information
johnjbarton authored and lusarz committed Oct 13, 2018
1 parent 4651524 commit f28a454
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions lib/server.js
Expand Up @@ -57,7 +57,7 @@ class Server extends KarmaEventEmitter {
super()
logger.setupFromConfig(cliOptions)

this.log = logger.create()
this.log = logger.create('karma-server')

this.loadErrors = []

Expand Down Expand Up @@ -124,7 +124,9 @@ class Server extends KarmaEventEmitter {
this._boundServer = boundServer
this._injector.invoke(this._start, this)
})
.catch(this.dieOnError.bind(this))
.catch((err) => {
this.dieOnError(`Server start failed on port ${config.port}: ${err}`)
})
}

get (token) {
Expand Down Expand Up @@ -156,7 +158,9 @@ class Server extends KarmaEventEmitter {
const singleRunBrowsers = new BrowserCollection(new EventEmitter())
let singleRunBrowserNotCaptured = false

webServer.on('error', this.dieOnError.bind(this))
webServer.on('error', (err) => {
this.dieOnError(`Webserver fail ${err}`)
})

const afterPreprocess = () => {
if (config.autoWatch) {
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/net-utils.js
Expand Up @@ -14,7 +14,7 @@ const NetUtils = {
if (err.code === 'EADDRINUSE' || err.code === 'EACCES') {
server.listen(++port, listenAddress)
} else {
reject(err)
reject(new Error(`Failed to bind ${port}: ` + (err.stack || err)))
}
})
.on('listening', () => {
Expand Down

0 comments on commit f28a454

Please sign in to comment.