Hey Aleksandr, sorry it took me a few days to get back to you. It's kind of hard to tell from your example, but it seems like you may be a little confused about what domains are supposed to do. The job of domains is to capture errors with enough context to provide state to you (the developer) or clients of your service. They're not really meant to be an error recovery mechanism. It makes sense to me that the response wouldn't get written out after the domain catches the error when notExist is called. I don't know enough about the details of your application to know when fs.readFile is being called, so I can't really say why 2 and higher aren't getting printed to stdout.
F On Wed, Sep 4, 2013 at 1:09 AM, Александр Крылов <[email protected]>wrote: > Hello! > > I use fs.readFile for load mail template. It's work fine in normal > situation. But if domain catch error, I don't read file (more > preciselyfs.readFile don't calls callback) > > Controller code: > > exports.default = function(req, res){ > notExist(); > } > > debugger code: > > if(log_to_mail){ > global.controllers.mail.sendMail('debug.html', 'Debug Info', > settings.devMail, { > err: err.message, > stack: err.stack, > url: url > }); > } > > > mailer code: > > var fs = require('fs'); > function getTemplate(template, params, cb){ > console.log(1); > fs.readFile(global.rootDir + '/templates/' + template, 'utf8', > function (err, tpl) { > console.log(2); > if(err){ > if(typeof cb == 'function') cb(err,null); > return; > } > console.log(3); > fs.readFile(global.rootDir + '/templates/layout.html', 'utf8', > function (err, layout) { > console.log(4); > if(err){ > if(typeof cb == 'function') cb(err,null); > return; > } > tpl = tpl.replace(/\{%(\w+)%\}/g, function(s, key) { > return params[key] || s; > }); > if(typeof cb == 'function') cb(err, > layout.replace('{%content%}', tpl)); > }); > }); > } > > exports.sendMail = function(template, subject, to, params, cb){ > var mailer = require('nodemailer'); > //.... settings > var mail = mailer.createTransport("SMTP", options); > getTemplate(template, params, function(err, html){ > console.log(123456); // test > > if(err){ > if(typeof cb == 'function') cb(err, null); > return; > } > var mailOptions = { > from: settings.mailFrom, // sender address > to: to, // list of receivers > subject: subject, // Subject line > html: html > } > mail.sendMail(mailOptions, function(error, response){ > console.log(response); > if(typeof cb == 'function') cb(error, response); > }); > }); > } > > > If I catch error and try get template then executed only console.log(1) > and after read file return to parent without call calback of fs.readFile. > But if I try to wrap notExist(); to setTimeout then code working fine and > shown all console.log > > Can you help me? > > -- > -- > Job Board: http://jobs.nodejs.org/ > Posting guidelines: > https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines > You received this message because you are subscribed to the Google > Groups "nodejs" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/nodejs?hl=en?hl=en > > --- > You received this message because you are subscribed to the Google Groups > "nodejs" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/groups/opt_out. > -- -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
