Invalid front-matter should not be cached #166

Open
opened 2023-11-27 11:21:50 +00:00 by Fil · 1 comment
Fil commented 2023-11-27 11:21:50 +00:00 (Migrated from github.com)

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>
}
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> } ```
DjebbZ commented 2025-08-08 10:12:51 +00:00 (Migrated from github.com)

Bumping the thread. As of today, using version "4.0.3", the bug still exists: invalid front-matter are cached, which break scenario where code using gray-matter is re-run several times.

Bumping the thread. As of today, using version "4.0.3", the bug still exists: invalid front-matter are cached, which break scenario where code using gray-matter is re-run several times.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
rtlabs-llm-agents/gms-gray-matter#166
No description provided.