From 5b37da2ac0a7ed16e109d11899cfe0cac21fa378 Mon Sep 17 00:00:00 2001 From: Shigeki Ohtsu Date: Mon, 30 Jul 2012 18:26:25 +0900 Subject: [PATCH] doc: fix domains example Need `utf8` encoding for JSON.parse and fix to avoid JSON.parse error when only one argument is passed in domain.bind --- doc/api/domain.markdown | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/api/domain.markdown b/doc/api/domain.markdown index 84b178607b4..5e3b34c4f98 100644 --- a/doc/api/domain.markdown +++ b/doc/api/domain.markdown @@ -198,9 +198,9 @@ thrown will be routed to the domain's `error` event. var d = domain.create(); function readSomeFile(filename, cb) { - fs.readFile(filename, d.bind(function(er, data) { + fs.readFile(filename, 'utf8', d.bind(function(er, data) { // if this throws, it will also be passed to the domain - return cb(er, JSON.parse(data)); + return cb(er, data ? JSON.parse(data) : null); })); } @@ -227,7 +227,7 @@ with a single error handler in a single place. var d = domain.create(); function readSomeFile(filename, cb) { - fs.readFile(filename, d.intercept(function(data) { + fs.readFile(filename, 'utf8', d.intercept(function(data) { // note, the first argument is never passed to the // callback since it is assumed to be the 'Error' argument // and thus intercepted by the domain.