Skip to content

Commit a0cb318

Browse files
committed
feat: prevent crashes caused by JSON parsing errors
1 parent 21e9c56 commit a0cb318

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/caddy/index.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -324,18 +324,22 @@ ${target.split(':')[0]}${https ? '' : ':80'} {
324324
// caddy log
325325
// eslint-disable-next-line no-console
326326
showCaddyLog && line && console.info(line)
327-
if (line.includes('Error:') || (line && JSON.parse(line).level === 'error')) {
328-
if (line.includes('parsing caddyfile tokens')) {
329-
consola.error('Caddyfile syntax error, please contact the author:\n', `${this.caddyfile}\n\n${line}\n`)
330-
await this.baseCleanup()
331-
process.exit()
332-
}
333-
else {
334-
consola.error(`${line}\n`)
335-
// child.kill()
336-
return reject(line)
327+
try {
328+
if (line.includes('Error:') || (line && JSON.parse(line).level === 'error')) {
329+
if (line.includes('parsing caddyfile tokens')) {
330+
consola.error('Caddyfile syntax error, please contact the author:\n', `${this.caddyfile}\n\n${line}\n`)
331+
await this.baseCleanup()
332+
process.exit()
333+
}
334+
else {
335+
consola.error(`${line}\n`)
336+
// child.kill()
337+
return reject(line)
338+
}
337339
}
338340
}
341+
catch {}
342+
339343
if (line.includes('config file changed'))
340344
consola.success('Detect added a new reverse proxy config, restarted.\n')
341345

0 commit comments

Comments
 (0)