From 25fbd4aeafd853627e21471924406df3f5a5ec9d Mon Sep 17 00:00:00 2001 From: Narek Hovhannisyan Date: Tue, 19 Nov 2024 20:40:57 +0400 Subject: [PATCH 1/2] fix(util): tune the logger behaviour in case of error stacks --- src/common/util/logger.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common/util/logger.ts b/src/common/util/logger.ts index 4d01d5960..5511292e6 100644 --- a/src/common/util/logger.ts +++ b/src/common/util/logger.ts @@ -14,8 +14,8 @@ export const logger = winston.createLogger({ align(), printf( (info: any) => - `[${info.timestamp}] ${info.level}: ${info.message} -${info.stack || ''}` + `[${info.timestamp}] ${info.stack || `${info.level}: ${info.message}`} +` ) ), transports: [new winston.transports.Console()], From 9e2dacd2dfef80827d8c39ec880d12234722719d Mon Sep 17 00:00:00 2001 From: Narek Hovhannisyan Date: Tue, 19 Nov 2024 20:45:28 +0400 Subject: [PATCH 2/2] fix(util): handle yaml fail cases --- src/common/util/yaml.ts | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/common/util/yaml.ts b/src/common/util/yaml.ts index beaedd71f..036fb4451 100644 --- a/src/common/util/yaml.ts +++ b/src/common/util/yaml.ts @@ -2,25 +2,36 @@ import * as fs from 'fs/promises'; import * as path from 'path'; import * as YAML from 'js-yaml'; +import {ERRORS} from '@grnsft/if-core/utils'; + +const {ReadFileError, WriteFileError} = ERRORS; /** * Reads and parses `yaml` file to object. */ export const openYamlFileAsObject = async (filePath: string): Promise => { - const yamlFileBuffer = await fs.readFile(filePath, 'utf8'); + try { + const yamlFileBuffer = await fs.readFile(filePath, 'utf8'); - return YAML.load(yamlFileBuffer) as T; + return YAML.load(yamlFileBuffer) as T; + } catch (error: any) { + throw new ReadFileError(error.message); + } }; /** * Saves given `yaml` dump as a file. */ export const saveYamlFileAs = async (object: any, pathToFile: string) => { - const dirPath = path.dirname(pathToFile); - await fs.mkdir(dirPath, {recursive: true}); - const yamlString = YAML.dump(object, {noRefs: true}); + try { + const dirPath = path.dirname(pathToFile); + await fs.mkdir(dirPath, {recursive: true}); + const yamlString = YAML.dump(object, {noRefs: true}); - return fs.writeFile(pathToFile, yamlString); + return fs.writeFile(pathToFile, yamlString); + } catch (error: any) { + throw new WriteFileError(error.message); + } }; /**