Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please open the issue again: "More descriptive errors when used in node.js (include the error line)" #1152

Closed
totty90 opened this issue Jun 15, 2014 · 4 comments

Comments

@totty90
Copy link

totty90 commented Jun 15, 2014

Please open again: #1067 (comment)

Here is the update and is a real bug:

Hello!

So I should rephrase the problem:

  • if is a syntax error then the non descriptive error is thrown;
  • if for example a value is not defined a descriptive error is thrown;

Exemple A (descriptive):

File test.js

var requirejs = require('../node_modules/requirejs/bin/r'); // or just require('requirejs')
requirejs.config({nodeRequire: require}); // required in node.js?

requirejs(['test2'], function(a) {
  console.log(a)
});

File test2.js

define([], function(){
    return utils.generateErrors({
    })
})

Error

c:\web\gp\server\test2.js:2
    return utils.generateErrors({
           ^
ReferenceError: utils is not defined
    at c:\web\gp\server\test2.js:2:12
    at Object.context.execCb (c:\web\gp\node_modules\requirejs\bin\r.js:1898:33)
    at Object.Module.check (c:\web\gp\node_modules\requirejs\bin\r.js:1114:51)
    at Object.Module.enable (c:\web\gp\node_modules\requirejs\bin\r.js:1391:22)
    at Object.Module.init (c:\web\gp\node_modules\requirejs\bin\r.js:1022:26)
    at callGetModule (c:\web\gp\node_modules\requirejs\bin\r.js:1418:63)
    at Object.context.completeLoad (c:\web\gp\node_modules\requirejs\bin\r.js:1792:21)
    at Function.req.load (c:\web\gp\node_modules\requirejs\bin\r.js:2547:17)
    at Object.context.load (c:\web\gp\node_modules\requirejs\bin\r.js:1887:21)
    at Object.Module.load (c:\web\gp\node_modules\requirejs\bin\r.js:1068:29)

Here you can see that the error is at line 2 in test.js, utils is not defined and also shows me the column.

Exemple B (non descriptive):

File test.js

var requirejs = require('../node_modules/requirejs/bin/r'); // or just require('requirejs')
requirejs.config({nodeRequire: require}); // required in node.js?

requirejs(['test2'], function(a) {
  console.log(a)
});

File test2.js

define([], function(){
    return ?utils.generateErrors({
    })
})

Notice the ? added before utils.generateErrors({

Error

c:\web\gp\node_modules\requirejs\bin\r.js:381
        throw err;
              ^
Error: Evaluating C:/Windows/WinRg/web/gp/server/test2.js as module "test2" failed with error: SyntaxError: Unexpected token ?
    at Function.req.load (c:\web\gp\node_modules\requirejs\bin\r.js:2505:23)
    at Object.context.load (c:\web\gp\node_modules\requirejs\bin\r.js:1887:21)
    at Object.Module.load (c:\web\gp\node_modules\requirejs\bin\r.js:1068:29)
    at Object.Module.fetch (c:\web\gp\node_modules\requirejs\bin\r.js:1058:66)
    at Object.Module.check (c:\web\gp\node_modules\requirejs\bin\r.js:1088:26)
    at Object.Module.enable (c:\web\gp\node_modules\requirejs\bin\r.js:1391:22)
    at Object.context.enable (c:\web\gp\node_modules\requirejs\bin\r.js:1759:39)
    at Object.<anonymous> (c:\web\gp\node_modules\requirejs\bin\r.js:1376:33)
    at c:\web\gp\node_modules\requirejs\bin\r.js:372:23
    at each (c:\web\gp\node_modules\requirejs\bin\r.js:297:31)

Now please tell me where is the problem? I only know is in the test2 file, but at which line and what exactly is the problem is unknown..

From your example

test2.js

define([], function(){
    return name: 'a'
})

Error

c:\web\gp\node_modules\requirejs\bin\r.js:381
        throw err;
              ^
Error: Evaluating C:/Windows/WinRg/web/gp/server/test2.js as module "test2" failed with error: SyntaxError: Unexpected token :
    at Function.req.load (c:\web\gp\node_modules\requirejs\bin\r.js:2505:23)
    at Object.context.load (c:\web\gp\node_modules\requirejs\bin\r.js:1887:21)
    at Object.Module.load (c:\web\gp\node_modules\requirejs\bin\r.js:1068:29)
    at Object.Module.fetch (c:\web\gp\node_modules\requirejs\bin\r.js:1058:66)
    at Object.Module.check (c:\web\gp\node_modules\requirejs\bin\r.js:1088:26)
    at Object.Module.enable (c:\web\gp\node_modules\requirejs\bin\r.js:1391:22)
    at Object.context.enable (c:\web\gp\node_modules\requirejs\bin\r.js:1759:39)
    at Object.<anonymous> (c:\web\gp\node_modules\requirejs\bin\r.js:1376:33)
    at c:\web\gp\node_modules\requirejs\bin\r.js:372:23
    at each (c:\web\gp\node_modules\requirejs\bin\r.js:297:31)

Same problem with your code. Maybe you are not using requirejs like I do, or maybe I do it wrong, I don't know but nowadays I mainly guess what the problem might be or I copy paste the code in the browser, stuff like that just to find the problem, which is a real pain.
I hope you understand the problem better now.
Thanks for your support

@jrburke jrburke added this to the 2.1.16 milestone Sep 8, 2014
@jrburke
Copy link
Member

jrburke commented Sep 8, 2014

Thanks for providing some examples, that really helps! Looking into it, the syntax errors are caught at this point in the node.js adapter. However, printing out e.stack did not give line numbers or more details on the syntax error, just the type of stack seen above. The vm.runInThisContext docs indicate stderr may be where that info goes, but I am not sure yet how best to tie into that information. So keeping this open for now for further investigation. Not sure when I will get to it, so happy to have help identifying a fix.

@totty90
Copy link
Author

totty90 commented Sep 8, 2014

Thanks for paying attention to such an important problem... This is my main concern about requirejs, and I don't understand how this is only a problem for me.

@totty90
Copy link
Author

totty90 commented Oct 23, 2014

@jrburke Anyone already fixed this?

@jrburke
Copy link
Member

jrburke commented Feb 8, 2015

This seems fixed now without any changes in r.js by using node 0.12, so going to close this out. Unfortunately, there are not enough hooks into vm.runInThisContext in older node versions to get to the information. With node 0.12, I see this sort of error now on the commandline (where test2 had a ?malformed as its text on its second line:

Error: Evaluating /Users/jr/git/requirejs/r.js/tests/node/nodeError/test2.js as module "test2" failed with error: SyntaxError: /Users/jr/git/requirejs/r.js/tests/node/nodeError/test2.js:2
    return ?malformed;
           ^
Unexpected token ?
    at Function.req.load (/Users/jr/git/requirejs/r.js/r.js:2516:23)
    at Object.context.load (/Users/jr/git/requirejs/r.js/r.js:1897:21)
    at Object.Module.load (/Users/jr/git/requirejs/r.js/r.js:1078:29)
    at Object.Module.fetch (/Users/jr/git/requirejs/r.js/r.js:1068:66)
    at Object.Module.check (/Users/jr/git/requirejs/r.js/r.js:1098:26)
    at Object.Module.enable (/Users/jr/git/requirejs/r.js/r.js:1401:22)
    at Object.context.enable (/Users/jr/git/requirejs/r.js/r.js:1769:39)
    at Object.<anonymous> (/Users/jr/git/requirejs/r.js/r.js:1386:33)
    at /Users/jr/git/requirejs/r.js/r.js:382:23
    at each (/Users/jr/git/requirejs/r.js/r.js:307:31)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants