Skip to content

Commit 5a175aa

Browse files
Temporary fix for a bug caused by nodeca/js-yaml#153
1 parent 04fbee2 commit 5a175aa

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

lib/yaml.js

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/* eslint lines-around-comment: [2, {beforeBlockComment: false}] */
22
'use strict';
33

4-
var yaml = require('js-yaml');
4+
var yaml = require('js-yaml'),
5+
ono = require('ono');
56

67
/**
78
* Simple YAML parsing functions, similar to {@link JSON.parse} and {@link JSON.stringify}
@@ -15,7 +16,18 @@ module.exports = {
1516
* @returns {*}
1617
*/
1718
parse: function yamlParse(text, reviver) {
18-
return yaml.safeLoad(text);
19+
try {
20+
return yaml.safeLoad(text);
21+
}
22+
catch (e) {
23+
if (e instanceof Error) {
24+
throw e;
25+
}
26+
else {
27+
// https://github.com/nodeca/js-yaml/issues/153
28+
throw ono(e, e.message);
29+
}
30+
}
1931
},
2032

2133
/**
@@ -27,7 +39,18 @@ module.exports = {
2739
* @returns {string}
2840
*/
2941
stringify: function yamlStringify(value, replacer, space) {
30-
var indent = (typeof space === 'string' ? space.length : space) || 2;
31-
return yaml.safeDump(value, {indent: indent});
42+
try {
43+
var indent = (typeof space === 'string' ? space.length : space) || 2;
44+
return yaml.safeDump(value, {indent: indent});
45+
}
46+
catch (e) {
47+
if (e instanceof Error) {
48+
throw e;
49+
}
50+
else {
51+
// https://github.com/nodeca/js-yaml/issues/153
52+
throw ono(e, e.message);
53+
}
54+
}
3255
}
3356
};

0 commit comments

Comments
 (0)