safeLoad(): Make options optional #61

mk-pmb opened this Issue Feb 9, 2013 · 3 comments


None yet
4 participants

mk-pmb commented Feb 9, 2013

When calling YAML.safeLoad(content) without a second argument (options), I get this error:

  var index, length, key, sourceKeys = Object.keys(source);
TypeError: Object.keys called on non-object
    at Function.keys (native)

Passing an empty object literal ({}) fixes the problem but looks out of place.

$ npm ls js-yaml
+-- js-yaml@2.0.0

dervus closed this in fcb2d2e Feb 9, 2013


dervus commented Feb 9, 2013

Fixed. Thanks!


puzrin commented Feb 9, 2013

published 2.0.1 with fix. please, check that it's ok.

In the README example code, a second argument is passed to safeLoad which is a string and not an object:

// Get document, or throw exception on error
try {
  var doc = yaml.safeLoad(fs.readFileSync('/home/ixti/example.yml', 'utf8'));
} catch (e) {

That code gives me the same error [TypeError: Object.keys called on non-object].
But when I remove , 'utf8', it's all good. Why is that happening?

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