Skip to content

Invalid front-matter should not be cached #166

Open
@Fil

Description

In case of an error, the result should not be cached. Currently the second call with the same invalid contents returns a (wrong) value.

❯ node
Welcome to Node.js v20.3.0.
Type ".help" for more information.
> const matter = require('gray-matter');
undefined
> matter("---\n{}+\n---\n")
Uncaught:
YAMLException: end of the stream or a document separator is expected at line 2, column 3:
    {}+
      ^
    at generateError (node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/loader.js:167:10)
    at throwError (node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/loader.js:173:9)
    at readDocument (node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/loader.js:1545:5)
    at loadDocuments (node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/loader.js:1588:5)
    at load (node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/loader.js:1614:19)
    at Object.safeLoad (node_modules/gray-matter/node_modules/js-yaml/lib/js-yaml/loader.js:1637:10)
    at module.exports (node_modules/gray-matter/lib/parse.js:12:17)
    at parseMatter (node_modules/gray-matter/index.js:109:17)
    at matter (node_modules/gray-matter/index.js:50:10) {
  reason: 'end of the stream or a document separator is expected',
  mark: Mark {
    name: null,
    buffer: '\n{}+\n\x00',
    position: 3,
    line: 1,
    column: 2
  }
}
> matter("---\n{}+\n---\n")
{
  content: '---\n{}+\n---\n',
  data: {},
  isEmpty: false,
  excerpt: '',
  orig: <Buffer 2d 2d 2d 0a 7b 7d 2b 0a 2d 2d 2d 0a>
}

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions