Skip to content

Commit

Permalink
fix: handle error when building schema
Browse files Browse the repository at this point in the history
The code changes in pylon-dev/src/index.ts now include error handling
when building the schema. If an error occurs during the build process,
the server will be killed and the error will be logged.
This ensures that the server is not left running in an inconsistent state.

In the addition, the development server no longer exits when a build error
occurs. When a user makes a syntax error and fixes it afterwards, the
service is up and running again without the need to manually restart it.
  • Loading branch information
schettn committed Sep 11, 2024
1 parent cbcccee commit 1aa9c42
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 12 deletions.
10 changes: 7 additions & 3 deletions packages/pylon-builder/src/bundler/bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,14 @@ export class Bundler {
const folder = path.dirname(this.sfiFilePath)

chokidar.watch(folder).on('change', async () => {
const changedSchema = await buildOnce()
try {
const changedSchema = await buildOnce()

if (options.onWatch) {
options.onWatch(changedSchema)
if (options.onWatch) {
options.onWatch(changedSchema)
}
} catch (e) {
consola.error(e)
}
})
}
Expand Down
53 changes: 44 additions & 9 deletions packages/pylon-dev/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,26 +160,46 @@ async function main(options: ArgOptions, command: Command) {
outputFilePath: `./.pylon`,
watch: true,
onWatch: async (schemaChanged: boolean) => {
const isServerRunning = currentProc !== null

if (isServerRunning) {
consola.start('[Pylon]: Reloading server')
} else {
consola.start('[Pylon]: Starting server')
}

await serve(schemaChanged)

consola.start('[Pylon]: Reloading server')
if (isServerRunning) {
consola.ready('[Pylon]: Server reloaded')
} else {
consola.ready('[Pylon]: Server started')

consola.box(`
Pylon is up and running!
Press \`Ctrl + C\` to stop the server.
Encounter any issues? Report them here:
https://github.com/getcronit/pylon/issues
We value your feedback—help us make Pylon even better!
`)
}

if (schemaChanged) {
consola.info('[Pylon]: Schema updated')
}
}
})
} catch (e) {
consola.error("[Pylon]: Couldn't build schema", e)
}

consola.success('[Pylon]: Schema built')
consola.success('[Pylon]: Schema built')

consola.start('[Pylon]: Starting server')
await serve(true)
consola.ready('[Pylon]: Server started')
consola.start('[Pylon]: Starting server')
await serve(true)
consola.ready('[Pylon]: Server started')

consola.box(`
consola.box(`
Pylon is up and running!
Press \`Ctrl + C\` to stop the server.
Expand All @@ -189,6 +209,21 @@ async function main(options: ArgOptions, command: Command) {
We value your feedback—help us make Pylon even better!
`)
} catch (e) {
consola.error("[Pylon]: Couldn't build schema", e)

// Kill the server if it's running
const proc = currentProc as ChildProcess | null
if (proc) {
proc.removeAllListeners()

kill(proc.pid, 'SIGINT', err => {
if (err) {
consola.error(err)
}
})
}
}
}

program.parse()

0 comments on commit 1aa9c42

Please sign in to comment.