CrabDude / trycatch

An asynchronous domain-based exception handler with long stack traces for node.js
MIT License
246 stars 17 forks source link

Error not catched #34

Closed JXBAR closed 9 years ago

JXBAR commented 10 years ago

Hi, i dont know where to put my message so i'll just write it there. I've read a lot about your very interesting plugin but i just cant get it work properly. I threw my exception in the try function, and handle it on the catch callback.The nodejs process just crash.

exports.newTag = function(req,res)
{
  trycatch(function()
  {
    var label = req.body.label;
    if(!label)
    {
      var error = new Error("Veuillez entrer un label pour le tag");
      error.custom = true;
      throw error;
    }
    database.Tag.count({label:label},function(err,count)
    {
      if(err) throw err;
      if(count> 0)
      {
        var error = new Error("Le tag existe déjà, entrez un autre nom");
        error.custom = true;
        throw error;
      }

      var tag = 
      {
        label: label
      };
      tag = new database.Tag(tag);
      tag.save(function(err)
      {
        if(err) throw err;
        return res.json({ok:true,tag:tag});
      });

    })

  },function(err)
  {
    console.error(err.stack);
    if(err.custom)
    {
      return res.json({ok:false,msg:error.message});
    }
    return res.json({ok:false,msg:"Désolé, une erreur est survenue"}); 
  });
 }
CrabDude commented 10 years ago

Your code looks good.

What package/module is "database"? Could you try and reduce your code to the minimum reproducible case?

Also, please add the following to your code and paste the output here:

process.on('uncaughtException', function(err) {
  console.log(err.stack);
});
CrabDude commented 10 years ago

Any update?

JXBAR commented 10 years ago

Hi, I'm sorry i didn't post sooner . I am now reducing the code to the minimum and i will post it as soon as possible. Thanks.

CrabDude commented 10 years ago

Try the latest version v1.5.4. There's a lot of refinements and improvements I've made to the code since you filed this bug (around v1.0.6). I suspect if you have an issue, it's very likely it's been fixed.

CrabDude commented 10 years ago

Any update? =)

CrabDude commented 9 years ago

Closing. Let me know if you are able to reproduce.