From c1a1d3a885aa14adf89405d8b737272678e4e814 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Uhl=C3=AD=C5=99?= Date: Tue, 10 May 2022 17:56:30 +0200 Subject: [PATCH] fix: proper error handling when conf does not exists (#106) --- src/utils/config-sources.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/utils/config-sources.ts b/src/utils/config-sources.ts index f8f4af5..d562b43 100644 --- a/src/utils/config-sources.ts +++ b/src/utils/config-sources.ts @@ -16,16 +16,26 @@ export function stripCommit(version: string): string { async function searchPackageJson(): Promise { const expectedPath = path.join(process.cwd(), 'package.json') - const pkgJson = JSON.parse(await readFile(expectedPath, { encoding: 'utf8' })) - return pkgJson?.engines?.bee + try { + const pkgJson = JSON.parse(await readFile(expectedPath, { encoding: 'utf8' })) + + return pkgJson?.engines?.bee + } catch (e) { + return undefined + } } async function searchBeeFactory(): Promise { const expectedPath = path.join(process.cwd(), '.beefactory.json') - const pkgJson = JSON.parse(await readFile(expectedPath, { encoding: 'utf8' })) - return pkgJson?.version + try { + const pkgJson = JSON.parse(await readFile(expectedPath, { encoding: 'utf8' })) + + return pkgJson?.version + } catch (e) { + return undefined + } } export async function findBeeVersion(): Promise {