TypeError thrown at undefined values #54

Closed
smirea opened this Issue Feb 28, 2014 · 2 comments

Comments

Projects
None yet
2 participants

smirea commented Feb 28, 2014

If u pass in an undefined value, it is not caught by absurd. It would be nice if absurd would tell you where the error happen by throwing its own or notify you in some other way that you probably did something wrong :)

example:

return {
  body: { width: undefined, }
}

Error: (no mentioned of where in the file it happened... :( )

Running "absurd:cssmin" (absurd) task
Error: '/Users/mozilla/Dropbox/www/nybl/kiwi/src/absurd/CommentBox.css.js'. [TypeError: Cannot call method 'toString' of undefined] TypeError: Cannot call method 'toString' of undefined
    at Object.add (/Users/mozilla/Dropbox/www/nybl/kiwi/node_modules/grunt-absurd/node_modules/absurd/lib/api/add.js:168:16)
    at Object.add (/Users/mozilla/Dropbox/www/nybl/kiwi/node_modules/grunt-absurd/node_modules/absurd/lib/API.js:117:16)
    at module.exports (/Users/mozilla/Dropbox/www/nybl/kiwi/src/absurd/CommentBox.css.js:39:7)
    at importFile (/Users/mozilla/Dropbox/www/nybl/kiwi/node_modules/grunt-absurd/node_modules/absurd/lib/api/import.js:37:26)
    at Object.<anonymous> (/Users/mozilla/Dropbox/www/nybl/kiwi/node_modules/grunt-absurd/node_modules/absurd/lib/api/import.js:47:4)
    at Object.import (/Users/mozilla/Dropbox/www/nybl/kiwi/node_modules/grunt-absurd/node_modules/absurd/lib/API.js:117:16)
    at /Users/mozilla/Dropbox/www/nybl/kiwi/src/absurd/absurd.js:16:15
    at Array.map (native)
    at module.exports (/Users/mozilla/Dropbox/www/nybl/kiwi/src/absurd/absurd.js:15:11)
    at importFile (/Users/mozilla/Dropbox/www/nybl/kiwi/node_modules/grunt-absurd/node_modules/absurd/lib/api/import.js:37:26)
Owner

krasimir commented Feb 28, 2014

I admit that absurd has a problem the error reporting as well as with the usage of the compiled file into the browser. It is a little bit difficult to find out where the style is defined. Especially if you use combineSelectors: true. Let's keep this issue open and I'll think about putting try-catch blocks here and there to see what is the effect.

krasimir added a commit that referenced this issue Mar 3, 2014

Owner

krasimir commented Mar 3, 2014

I added a try-catch block in the add method. So now if you do:

api.add({
    body: {
        width: undefined,
        padding: '20px'
    }
}).compile(function(err, css) {
    console.log(css);           
    done();
}, { minify: false });

You will get:

Error: Error adding: {"body":{"padding":"20px"}}

So, it tells you which object causes the problem.

P.S.
test case here https://github.com/krasimir/absurd/blob/master/tests/experimental/error.reporting.spec.js

@krasimir krasimir closed this Mar 3, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment