3

This is driving me crazy. I have the code below and when I run it, I only have debug-1 print. If I comment out the where declaration I get debug-1 and debug-2 to print.

        console.log( 'debug-1' )
        var where = {
            compound_id: study.compound_id,
            species: {
                "like": ( species + "*" )
            },
            study_start: {
                "<=": study.study_start
            },
            study_start: {
                ">=": threeYearsBeforeStudy
            }
        }
        console.log( 'debug-2' )

Super peculiar. I have this block inside a promise, but I'm sure that shouldn't be an issue.

Anthony
  • 13,434
  • 14
  • 60
  • 80

1 Answers1

9

Add the code

process.on('unhandledRejection', console.log.bind(console))

to the top of your node file after your dependencies. That will let you know what is going wrong, it seems you are running into an error with your promise without handling it anywhere.

dvlsg
  • 5,378
  • 2
  • 29
  • 34
Anthony
  • 13,434
  • 14
  • 60
  • 80
  • Yep, not sure why you were down voted at first. Didn't know bout that snippet. Lead me to know I was trying to use an undefined variable. Thanks. –  Apr 06 '16 at 18:17
  • Yeah me neither, I saw you got downvoted as well and gave you an upvote, stuff like that just happens on SO. If you were able to get it fixed would appreciate it if you accepted this as an answer, thanks! – Anthony Apr 06 '16 at 18:20
  • To me this doesn't look like an answer in any way shape or form, it's a reqeust for clarification, which belongs in the comments. The "answer" would of course be "you're variable is undefined", but we can't come to that conclusion without clarification in the question, so the question should be closed. – Kevin B Apr 06 '16 at 19:29
  • Well the answer isn't your variable is undefined, the answer is that the reason nothing is coming to the logs is that you're not handling that error, and probably you have an undefined variable which is not being displayed to you and causing the code not to run, which I answered above. Let me change the name of the question though if I can – Anthony Apr 06 '16 at 20:23
  • Right, but the answer is still "your variable is undefined", not "this is how you catch uncaught errors" which i would have been more than happy to dupe close with http://stackoverflow.com/questions/7310521/node-js-best-practice-exception-handling/7313005#7313005 which provides a far more comprehensive guide of how to properly handle errors in node.js, including how to use .catch with promises. – Kevin B Apr 06 '16 at 20:54