Prevent exiting when an exception is uncaught

This commit is contained in:
Asher 2020-03-30 15:52:11 -05:00
parent 599670136d
commit 6c104c016e
No known key found for this signature in database
GPG Key ID: D63C1EF81242354A
2 changed files with 16 additions and 9 deletions

View File

@ -14,6 +14,13 @@ import { SshProvider } from "./ssh/server"
import { generateCertificate, generatePassword, generateSshHostKey, hash, open } from "./util"
import { ipcMain, wrap } from "./wrapper"
process.on("uncaughtException", (error) => {
logger.error(`Uncaught exception: ${error.message}`)
if (typeof error.stack !== "undefined") {
logger.error(error.stack)
}
})
let pkg: { version?: string; commit?: string } = {}
try {
pkg = require("../../package.json")
@ -73,7 +80,7 @@ const main = async (args: Args): Promise<void> => {
logger.info(`code-server ${version} ${commit}`)
let sshPort = ""
let sshPort: number | undefined
if (!args["disable-ssh"] && options.sshHostKey) {
const sshProvider = httpServer.registerHttpProvider("/ssh", SshProvider, options.sshHostKey as string)
try {
@ -84,7 +91,7 @@ const main = async (args: Args): Promise<void> => {
}
const serverAddress = await httpServer.listen()
logger.info(`Server listening on ${serverAddress}`)
logger.info(`HTTP server listening on ${serverAddress}`)
if (auth === AuthType.Password && !process.env.PASSWORD) {
logger.info(` - Password is ${originalPassword}`)
@ -108,19 +115,19 @@ const main = async (args: Args): Promise<void> => {
logger.info(" - Not serving HTTPS")
}
logger.info(` - Automatic updates are ${update.enabled ? "enabled" : "disabled"}`)
logger.info(`Automatic updates are ${update.enabled ? "enabled" : "disabled"}`)
if (sshPort) {
logger.info(` - SSH Server - Listening :${sshPort}`)
if (typeof sshPort !== "undefined") {
logger.info(`SSH server listening on localhost:${sshPort}`)
} else {
logger.info(" - SSH Server - Disabled")
logger.info("SSH server disabled")
}
if (serverAddress && !options.socket && args.open) {
// The web socket doesn't seem to work if browsing with 0.0.0.0.
const openAddress = serverAddress.replace(/:\/\/0.0.0.0/, "://localhost")
await open(openAddress).catch(console.error)
logger.info(` - Opened ${openAddress}`)
logger.info(`Opened ${openAddress}`)
}
}

View File

@ -24,11 +24,11 @@ export class SshProvider extends HttpProvider {
})
}
public async listen(): Promise<string> {
public async listen(): Promise<number> {
return new Promise((resolve, reject) => {
this.sshServer.once("error", reject)
this.sshServer.listen(() => {
resolve(this.sshServer.address().port.toString())
resolve(this.sshServer.address().port)
})
})
}