* Write HTML content to a temporary file and open the file in a browser
(html?: string)
| 219 | * Write HTML content to a temporary file and open the file in a browser |
| 220 | */ |
| 221 | async function writeHtmlToTempFile(html?: string): Promise<void> { |
| 222 | if (!html) { |
| 223 | return; |
| 224 | } |
| 225 | |
| 226 | try { |
| 227 | const tempFile = temp.path({ prefix: 'sme-result-', suffix: '.html' }); |
| 228 | |
| 229 | fs.writeFileSync(tempFile, html); |
| 230 | |
| 231 | const childProcess = await open(tempFile); |
| 232 | |
| 233 | if (childProcess.stderr) { |
| 234 | // Catch error output from child process |
| 235 | childProcess.stderr.once('data', (error: Buffer) => { |
| 236 | // TODO: Figure out why `#< CLIXML` ends up in stderr. Maybe we should simply ignore it |
| 237 | if (error.toString().trim() !== '#< CLIXML') { |
| 238 | logError({ code: 'CannotOpenTempFile', tempFile, error }); |
| 239 | } |
| 240 | }); |
| 241 | } |
| 242 | } catch (error) { |
| 243 | throw new AppError({ code: 'CannotCreateTempFile' }, error); |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | function outputErrors({ errors }: ExploreResult): void { |
| 248 | if (errors.length === 0) { |