Skip to content

Commit 5390772

Browse files
logging: return serialization error to callback instead of throwing (#2081)
1 parent b1602c1 commit 5390772

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

handwritten/logging/src/log.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -630,9 +630,17 @@ Log.prototype.decorateEntries_ = function(entries, callback) {
630630
entry = self.entry(entry);
631631
}
632632

633-
var decoratedEntry = entry.toJSON({
634-
removeCircular: self.removeCircular_
635-
});
633+
var decoratedEntry;
634+
635+
try {
636+
decoratedEntry = entry.toJSON({
637+
removeCircular: self.removeCircular_
638+
});
639+
} catch(e) {
640+
callback(e);
641+
return;
642+
}
643+
636644
decoratedEntry.logName = self.formattedName_;
637645

638646
self.metadata_.assignDefaultResource(decoratedEntry, function(err, entry) {

handwritten/logging/test/log.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,20 @@ describe('Log', function() {
696696
log.decorateEntries_([entry], assert.ifError);
697697
});
698698

699+
it('should exec callback with error from serialization', function(done) {
700+
var error = new Error('Error.');
701+
702+
var entry = new Entry();
703+
entry.toJSON = function() {
704+
throw error;
705+
};
706+
707+
log.decorateEntries_([entry], function(err) {
708+
assert.strictEqual(err, error);
709+
done();
710+
});
711+
});
712+
699713
it('should assign the log name', function(done) {
700714
log.decorateEntries_([{}], function(err, decoratedEntries) {
701715
assert.ifError(err);

0 commit comments

Comments
 (0)