Compare commits

...

3 Commits

Author SHA1 Message Date
Rich Harris
31110a5326 -> v0.13.5 2018-06-26 18:30:46 -04:00
Rich Harris
667a68768c Merge pull request #294 from sveltejs/gh-289
fix handling of fatal errors
2018-06-26 18:29:56 -04:00
Rich Harris
5075981a90 fix handling of fatal errors - fixes #289 2018-06-26 13:49:11 -04:00
5 changed files with 41 additions and 14 deletions

View File

@@ -1,5 +1,9 @@
# sapper changelog # sapper changelog
## 0.13.5
* Fix handling of fatal errors ([#289](https://github.com/sveltejs/sapper/issues/289))
## 0.13.4 ## 0.13.4
* Focus `<body>` after navigation ([#287](https://github.com/sveltejs/sapper/issues/287)) * Focus `<body>` after navigation ([#287](https://github.com/sveltejs/sapper/issues/287))

View File

@@ -1,6 +1,6 @@
{ {
"name": "sapper", "name": "sapper",
"version": "0.13.4", "version": "0.13.5",
"description": "Military-grade apps, engineered by Svelte", "description": "Military-grade apps, engineered by Svelte",
"main": "dist/middleware.ts.js", "main": "dist/middleware.ts.js",
"bin": { "bin": {

View File

@@ -33,6 +33,7 @@ class Watcher extends EventEmitter {
server: Deferred; server: Deferred;
}; };
crashed: boolean;
restarting: boolean; restarting: boolean;
current_build: { current_build: {
changed: Set<string>; changed: Set<string>;
@@ -130,10 +131,16 @@ class Watcher extends EventEmitter {
// TODO watch the configs themselves? // TODO watch the configs themselves?
const compilers = create_compilers({ webpack: this.dirs.webpack }); const compilers = create_compilers({ webpack: this.dirs.webpack });
let log = '';
const emitFatal = () => { const emitFatal = () => {
this.emit('fatal', <events.FatalEvent>{ this.emit('fatal', <events.FatalEvent>{
message: `Server crashed` message: `Server crashed`,
log
}); });
this.crashed = true;
this.proc = null;
}; };
this.watch(compilers.server, { this.watch(compilers.server, {
@@ -149,18 +156,30 @@ class Watcher extends EventEmitter {
this.deferreds.client.promise.then(() => { this.deferreds.client.promise.then(() => {
const restart = () => { const restart = () => {
ports.wait(this.port).then((() => { log = '';
this.emit('ready', <events.ReadyEvent>{ this.crashed = false;
port: this.port,
process: this.proc
});
this.deferreds.server.fulfil(); ports.wait(this.port)
.then((() => {
this.emit('ready', <events.ReadyEvent>{
port: this.port,
process: this.proc
});
this.dev_server.send({ this.deferreds.server.fulfil();
status: 'completed'
this.dev_server.send({
status: 'completed'
});
}))
.catch(err => {
if (this.crashed) return;
this.emit('fatal', <events.FatalEvent>{
message: `Server is not listening on port ${this.port}`,
log
});
}); });
}));
}; };
if (this.proc) { if (this.proc) {
@@ -180,10 +199,12 @@ class Watcher extends EventEmitter {
}); });
this.proc.stdout.on('data', chunk => { this.proc.stdout.on('data', chunk => {
log += chunk;
this.emit('stdout', chunk); this.emit('stdout', chunk);
}); });
this.proc.stderr.on('data', chunk => { this.proc.stderr.on('data', chunk => {
log += chunk;
this.emit('stderr', chunk); this.emit('stderr', chunk);
}); });
@@ -301,7 +322,7 @@ class Watcher extends EventEmitter {
if (err) { if (err) {
this.emit('error', <events.ErrorEvent>{ this.emit('error', <events.ErrorEvent>{
type: name, type: name,
error: err message: err.message
}); });
} else { } else {
const messages = format_messages(stats); const messages = format_messages(stats);

View File

@@ -12,6 +12,7 @@ export type ErrorEvent = {
export type FatalEvent = { export type FatalEvent = {
message: string; message: string;
log?: string;
}; };
export type InvalidEvent = { export type InvalidEvent = {

View File

@@ -36,11 +36,12 @@ export function dev(opts: { port: number, open: boolean }) {
watcher.on('error', (event: events.ErrorEvent) => { watcher.on('error', (event: events.ErrorEvent) => {
console.log(`${colors.red(`${event.type}`)}`); console.log(`${colors.red(`${event.type}`)}`);
console.log(`${colors.red(event.error.message)}`); console.log(`${colors.red(event.message)}`);
}); });
watcher.on('fatal', (event: events.FatalEvent) => { watcher.on('fatal', (event: events.FatalEvent) => {
console.log(`${colors.bold.red(`> ${event.error.message}`)}`); console.log(`${colors.bold.red(`> ${event.message}`)}`);
if (event.log) console.log(event.log);
}); });
watcher.on('build', (event: events.BuildEvent) => { watcher.on('build', (event: events.BuildEvent) => {