1
1
/* eslint lines-around-comment: [2, {beforeBlockComment: false}] */
2
2
'use strict' ;
3
3
4
- var yaml = require ( 'js-yaml' ) ;
4
+ var yaml = require ( 'js-yaml' ) ,
5
+ ono = require ( 'ono' ) ;
5
6
6
7
/**
7
8
* Simple YAML parsing functions, similar to {@link JSON.parse} and {@link JSON.stringify}
@@ -15,7 +16,18 @@ module.exports = {
15
16
* @returns {* }
16
17
*/
17
18
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
+ }
19
31
} ,
20
32
21
33
/**
@@ -27,7 +39,18 @@ module.exports = {
27
39
* @returns {string }
28
40
*/
29
41
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
+ }
32
55
}
33
56
} ;
0 commit comments