Skip to content

Commit 35a3cfc

Browse files
imlucaskangas
authored andcommitted
fix(ui): Schema properly handles stream errors
1 parent 576868c commit 35a3cfc

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

scout-client/lib/client.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ Client.prototype.createReadStream = function(_id, data) {
736736
return debug('proxy already transferred');
737737
}
738738
});
739-
this.on('readable', function() {
739+
this.once('readable', function() {
740740
debug('client readable');
741741
var src = client.createReadStream(_id, data);
742742
src.on('data', proxy.emit.bind(proxy, 'data'));
@@ -752,6 +752,10 @@ Client.prototype.createReadStream = function(_id, data) {
752752
data = data || {};
753753
var stream = ss.createStream(this.io);
754754
ss(this.io).emit(_id, stream, data);
755-
return stream.pipe(EJSON.createParseStream());
755+
756+
var parser = EJSON.createParseStream();
757+
var res = stream.pipe(parser);
758+
stream.on('error', res.emit.bind(res, 'error'));
759+
return res;
756760
}
757761
};

scout-ui/src/home/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,14 @@ var CollectionView = AmpersandView.extend({
2525
app.statusbar.watch(this, this.schema);
2626

2727
this.schema.ns = this.model._id;
28+
this.listenTo(this.schema, 'error', this.onError);
2829
this.schema.fetch();
2930
},
3031
template: require('./collection.jade'),
32+
onError: function(schema, err) {
33+
// @todo: Figure out a good way to handle this (server is probably crashed).
34+
console.error('Error getting schema: ', err);
35+
},
3136
subviews: {
3237
fields: {
3338
waitFor: 'schema.fields',

scout-ui/src/models/index.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ window.scout = client;
1717

1818
var wrapError = require('./wrap-error');
1919

20+
/**
21+
* Catch-all for any client errors so we just log them instead of
22+
* stopping the app.
23+
*/
24+
client.on('error', function(err) {
25+
console.error(err);
26+
});
27+
2028
var SampledSchema = Schema.extend({
2129
fetch: function(options) {
2230
options = _.defaults((options || {}), {
@@ -28,7 +36,7 @@ var SampledSchema = Schema.extend({
2836
wrapError(this, options);
2937

3038
var model = this;
31-
var detect = this.stream()
39+
var parser = this.stream()
3240
.on('error', function(err) {
3341
options.error(err, 'error', err.message);
3442
})
@@ -40,7 +48,9 @@ var SampledSchema = Schema.extend({
4048

4149
model.trigger('request', model, {}, options);
4250
process.nextTick(function() {
43-
client.sample(model.ns, options).pipe(detect);
51+
client.sample(model.ns, options)
52+
.on('error', parser.emit.bind(parser, 'error'))
53+
.pipe(parser);
4454
});
4555
}
4656
});

0 commit comments

Comments
 (0)