File tree 1 file changed +17
-5
lines changed
1 file changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -62,14 +62,26 @@ export default class HtmlBeautifier {
62
62
} ) ;
63
63
64
64
htmlbeautifier . on ( "exit" , ( code ) => {
65
+ const errorMessage = Buffer . concat ( stderrChunks ) . toString ( ) . trim ( ) ;
66
+
67
+ // Handle non-zero exit codes as errors
68
+ if ( code !== 0 ) {
69
+ return reject (
70
+ `Formatting failed with exit code ${ code } : ${ errorMessage } `
71
+ ) ;
72
+ }
73
+
74
+ // Handle case where output is empty but input was not
65
75
const formattedResult = Buffer . concat ( stdoutChunks ) . toString ( ) ;
66
76
const finalResult = this . handleFinalNewline ( input , formattedResult ) ;
67
- const errorMessage = Buffer . concat ( stderrChunks ) . toString ( ) ;
68
- if ( code && code !== 0 ) {
69
- reject ( `Failed with exit code ${ code } . ${ errorMessage } ` ) ;
70
- } else {
71
- resolve ( finalResult ) ;
77
+ if ( input . trim ( ) && finalResult . trim ( ) === "" ) {
78
+ return reject (
79
+ `Formatting failed: the output is unexpectedly empty despite non-empty input. ${ errorMessage } `
80
+ ) ;
72
81
}
82
+
83
+ // If no errors, resolve with the formatted result
84
+ resolve ( finalResult ) ;
73
85
} ) ;
74
86
75
87
htmlbeautifier . stdin . write ( input ) ;
You can’t perform that action at this time.
0 commit comments