From 37d613f93295b2154988dd2357f83dde95a1542a Mon Sep 17 00:00:00 2001 From: Anton Shubin <2spy4x@gmail.com> Date: Tue, 7 Apr 2020 21:50:16 +0300 Subject: [PATCH] fix(.oh-my-zsh/custom/getFirebaseProject.js): add error handling if "firebase-tools.json" was not found --- .oh-my-zsh/custom/getFirebaseProject.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/.oh-my-zsh/custom/getFirebaseProject.js b/.oh-my-zsh/custom/getFirebaseProject.js index f34fab6..a25eed0 100644 --- a/.oh-my-zsh/custom/getFirebaseProject.js +++ b/.oh-my-zsh/custom/getFirebaseProject.js @@ -1,7 +1,19 @@ -const json = require(`${process.env.HOME}/.config/configstore/firebase-tools.json`); +const { readFileSync } = require(`fs`); -const firebaseProjectName = json.activeProjects[process.argv[2]]; +const folderPath = process.argv[2]; +try { + const pathToFirebaseToolsJson = `${process.env.HOME}/.config/configstore/firebase-tools.json`; + const fileContent = readFileSync(pathToFirebaseToolsJson); + const firebaseToolsJson = JSON.parse(fileContent); + const firebaseProjectName = firebaseToolsJson.activeProjects[folderPath]; -if (firebaseProjectName) { - console.log(firebaseProjectName); + if (firebaseProjectName) { + console.log(firebaseProjectName); + } +} catch (error) { + if (error.code && error.code === "ENOENT") { + console.error(`Couldn't find file "${pathToFirebaseToolsJson}". Please create it with "$ firebase use " in your project folder.`); + } else { + console.error(error); + } } \ No newline at end of file