File tree Expand file tree Collapse file tree 1 file changed +19
-7
lines changed Expand file tree Collapse file tree 1 file changed +19
-7
lines changed Original file line number Diff line number Diff line change @@ -18,9 +18,15 @@ export const deserialize = <SHAPE = unknown>(
18
18
data : Stringable ,
19
19
options : { schema ?: ZodSchema < SHAPE > } = { } ,
20
20
) : SHAPE => {
21
- const validatedData = YAML . parse ( data . toString ( ) ) ;
22
- if ( options . schema ) return options . schema . parse ( validatedData ) ;
23
- return validatedData ;
21
+ try {
22
+ const validatedData = YAML . parse ( data . toString ( ) ) ;
23
+ if ( options . schema ) return options . schema . parse ( validatedData ) ;
24
+ return validatedData ;
25
+ } catch ( error ) {
26
+ throw new Error ( `Failed to parse YAML` , {
27
+ cause : error ,
28
+ } ) ;
29
+ }
24
30
} ;
25
31
26
32
/**
@@ -33,8 +39,14 @@ export const serialize = <SHAPE = any>(
33
39
data : SHAPE ,
34
40
options : { schema ?: ZodSchema < any , SHAPE > } = { } ,
35
41
) => {
36
- const validatedData = options . schema ? options . schema . parse ( data ) : data ;
37
- return YAML . stringify ( validatedData , {
38
- blockQuote : "literal" , // Avoid unnecessary whitespace on preview
39
- } ) ;
42
+ try {
43
+ const validatedData = options . schema ? options . schema . parse ( data ) : data ;
44
+ return YAML . stringify ( validatedData , {
45
+ blockQuote : "literal" , // Avoid unnecessary whitespace on preview
46
+ } ) ;
47
+ } catch ( error ) {
48
+ throw new Error ( `Failed to serialize YAML` , {
49
+ cause : error ,
50
+ } ) ;
51
+ }
40
52
} ;
You can’t perform that action at this time.
0 commit comments