From 1adf298632cb94d1187f5a0563a04a68055577e0 Mon Sep 17 00:00:00 2001 From: Eduard Marbach Date: Thu, 1 Aug 2024 17:08:45 +0200 Subject: [PATCH] refactor: add some logs --- index.ts | 1 + src/config.ts | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/index.ts b/index.ts index c166931..26cfb19 100644 --- a/index.ts +++ b/index.ts @@ -277,6 +277,7 @@ const run = async () => { if (IS_DRY_RUN) { logger.info("DryRun: Running in dry-run mode!"); } + const applicationConfig = getConfig(); await cloneRecyclarrTemplateRepo(); diff --git a/src/config.ts b/src/config.ts index a417c39..2284ec7 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,5 +1,6 @@ -import { readFileSync } from "fs"; +import { existsSync, readFileSync } from "fs"; import yaml from "yaml"; +import { logger } from "./logger"; import { YamlConfig } from "./types"; import { ROOT_PATH } from "./util"; @@ -24,6 +25,11 @@ export const getConfig = (): YamlConfig => { return config; } + if (!existsSync(CONFIG_LOCATION)) { + logger.error(`Config file in location "${CONFIG_LOCATION}" does not exists.`); + throw new Error("Config file not found."); + } + const file = readFileSync(CONFIG_LOCATION, "utf8"); config = yaml.parse(file, { customTags: [secretsTag] }) as YamlConfig; return config; @@ -34,6 +40,11 @@ export const getSecrets = () => { return secrets; } + if (!existsSync(SECRETS_LOCATION)) { + logger.error(`Secret file in location "${SECRETS_LOCATION}" does not exists.`); + throw new Error("Secret file not found."); + } + const file = readFileSync(SECRETS_LOCATION, "utf8"); config = yaml.parse(file); return config;