Skip to content

Commit

Permalink
Fix #58 - add error listener - first step
Browse files Browse the repository at this point in the history
  • Loading branch information
fdodino committed Oct 2, 2023
1 parent 0cb95f3 commit baeefce
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/commands/repl.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bold } from 'chalk'
import { bold, yellow } from 'chalk'
import { Command } from 'commander'
import cors from 'cors'
import express from 'express'
Expand Down Expand Up @@ -68,7 +68,6 @@ export default async function (autoImportPath: string | undefined, options: Opti
socket.emit('initDiagram', options)
socket.emit('updateDiagram', getDataDiagram(interpreter))
})

repl.prompt()
}

Expand Down Expand Up @@ -232,6 +231,17 @@ async function autocomplete(input: string): Promise<CompleterResult> {
async function initializeClient(options: Options) {
const app = express()
const server = http.createServer(app)

server.addListener('error', ({ port, code }: { port: string, code: string }) => {
console.info('')
if (code === 'EADDRINUSE') {
console.info(yellow(bold(`Ya tenés levantado un REPL en el puerto ${port}. Si querés levantar otra instancia, utilizá la opción '--new'.`)))
} else {
console.info(yellow(bold(`No se pudo levantar el REPL en el puerto ${port}, por un código de error "${code}.`)))
}
process.exit(1)
})

const io = new Server(server)

io.on('connection', socket => {
Expand Down Expand Up @@ -271,4 +281,4 @@ function newImport(importNode: Import, environment: Environment) {
return node.scope.register([imported.name!, imported])
}

export const replNode = (environment: Environment): Package => environment.getNodeByFQN<Package>('REPL')
export const replNode = (environment: Environment): Package => environment.getNodeByFQN<Package>('REPL')

0 comments on commit baeefce

Please sign in to comment.