From e9ab9d24acf48f4c3e519f035b89fd89018bf47d Mon Sep 17 00:00:00 2001 From: reeshika-h Date: Tue, 28 Oct 2025 15:45:15 +0530 Subject: [PATCH 1/5] updated error messages --- src/filesystem.ts | 17 +++++++++-------- src/index.ts | 7 ++++--- src/messages.ts | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 11 deletions(-) create mode 100644 src/messages.ts diff --git a/src/filesystem.ts b/src/filesystem.ts index 35565c6..2cae939 100644 --- a/src/filesystem.ts +++ b/src/filesystem.ts @@ -30,6 +30,7 @@ import { validateUnPublishAsset, sanitizePath } from './utils' +import { messages } from './messages' const debug = Debug('asset-store-filesystem') @@ -76,7 +77,7 @@ export class FSAssetStore { * @returns {Promise} returns the asset object, if successful. */ public download(asset) { - debug('Asset download invoked ' + JSON.stringify(asset)) + debug(messages.info.assetDownloadInitiated(asset)) return new Promise((resolve, reject) => { try { @@ -117,7 +118,7 @@ export class FSAssetStore { }) .catch(reject) } catch (error) { - debug(`${asset.uid} asset download failed`) + debug(messages.info.assetDownloadFailed(asset.uid)) return reject(error) } @@ -132,7 +133,7 @@ export class FSAssetStore { * @returns {Promise} returns the asset object, if successful. */ public delete(assets: IAsset[]) { - debug('Asset deletion called for', JSON.stringify(assets)) + debug(messages.info.assetDeletionInitiated(), JSON.stringify(assets)) const asset = assets[0] return new Promise((resolve, reject) => { @@ -147,11 +148,11 @@ export class FSAssetStore { .then(() => rimraf(folderPath)) .then(() => resolve(asset)) .catch((error) => { - debug(`Error while removing ${folderPath} asset file`); + debug(messages.info.assetFileRemovalError(folderPath)); return reject(error); }); } else { - debug(`${folderPath} did not exist!`) + debug(messages.info.folderPathNotExist(folderPath)) return resolve(asset) } @@ -169,7 +170,7 @@ export class FSAssetStore { * @returns {Promise} returns the asset object, if successful. */ public unpublish(asset: IAsset) { - debug(`Asset unpublish called ${JSON.stringify(asset)}`) + debug(messages.info.assetUnpublishInitiated(asset)) return new Promise((resolve, reject) => { try { @@ -181,11 +182,11 @@ export class FSAssetStore { .then(() => rimraf(filePath)) .then(() => resolve(asset)) .catch((error) => { - debug(`Error while removing ${filePath} asset file`); + debug(messages.info.assetFileRemovalError(filePath)); return reject(error); }); } - debug(`${filePath} did not exist!`) + debug(messages.info.filePathNotExist(filePath)) return resolve(asset) } catch (error) { diff --git a/src/index.ts b/src/index.ts index 174cfde..5eff9b0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,6 +9,7 @@ import { compact, merge } from 'lodash' import { join } from 'path' import { defaultConfig } from './config' import { FSAssetStore } from './filesystem' +import { messages } from './messages' let assetStoreConfig let assetStoreInstance @@ -45,7 +46,7 @@ export const getAssetLocation = (asset, config) => { if (asset[k]) { values.push(asset[k]) } else { - throw new TypeError(`The key ${keys[i]} did not exist on ${JSON.stringify(asset)}`) + throw new TypeError(messages.errors.keyNotExist(keys[i], asset)) } } else { values.push(keys[i]) @@ -89,7 +90,7 @@ export const getFileLocation = (asset, config) => { if (asset[k]) { values.push(asset[k]) } else { - throw new TypeError(`The key ${keys[i]} did not exist on ${JSON.stringify(asset)}`) + throw new TypeError(messages.errors.keyNotExist(keys[i], asset)) } } else { values.push(keys[i]) @@ -132,7 +133,7 @@ export function start(config) { assetStoreInstance = new FSAssetStore(assetStoreConfig) return resolve(assetStoreInstance) } catch (error) { - debug('Failed to load content-store due to', error) + debug(messages.errors.contentStoreLoadFailed(), error) reject(error) } }) diff --git a/src/messages.ts b/src/messages.ts new file mode 100644 index 0000000..1242816 --- /dev/null +++ b/src/messages.ts @@ -0,0 +1,37 @@ +/*! + * contentstack-sync-asset-store-filesystem + * copyright (c) Contentstack LLC + * MIT Licensed + */ + +/** + * Centralized error and log messages for the asset store filesystem + */ +export const messages = { + // Error messages + errors: { + keyNotExist: (key: string, asset: any) => + `The key '${key}' does not exist on: ${JSON.stringify(asset)}`, + contentStoreLoadFailed: () => + 'Failed to load content store:', + }, + + // Info/Debug messages + info: { + assetDownloadInitiated: (asset: any) => + `Asset download initiated for: ${JSON.stringify(asset)}`, + assetDownloadFailed: (uid: string) => + `Download failed for asset: ${uid}`, + assetDeletionInitiated: () => + 'Asset deletion initiated:', + assetFileRemovalError: (path: string) => + `An error occurred while removing the asset file at: ${path}`, + folderPathNotExist: (path: string) => + `Folder path does not exist: ${path}`, + assetUnpublishInitiated: (asset: any) => + `Asset unpublish initiated for: ${JSON.stringify(asset)}`, + filePathNotExist: (path: string) => + `File path does not exist: ${path}`, + }, +} + From 2ede308f6ad288d9db79115572ab532e44a667c6 Mon Sep 17 00:00:00 2001 From: reeshika-h Date: Wed, 29 Oct 2025 10:15:54 +0530 Subject: [PATCH 2/5] talisman fix --- .talismanrc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.talismanrc b/.talismanrc index dfec72f..27d2ffe 100644 --- a/.talismanrc +++ b/.talismanrc @@ -4,4 +4,8 @@ fileignoreconfig: - filecontent - filename: package-lock.json checksum: 20cc76958aec3163d9b695e49bcdfbef7244fc473e31f8eb69b88133622f4fb4 +- filename: src/index.ts + checksum: 3563972e6fef958b021444c41ef04f5f32e83d1d51f7faea62ad1633130b6f1a +- filename: src/messages.ts + checksum: 5fc01b165e2fec0c969b954b15ab9201eaabcdce766c8b007907377f015f0043 version: "" From 5ad38892418a05bc4d091b187ab6c691534feac4 Mon Sep 17 00:00:00 2001 From: reeshika-h Date: Fri, 31 Oct 2025 15:07:03 +0530 Subject: [PATCH 3/5] refactor: improve error handling for asset downloads by utilizing centralized message formatting --- src/filesystem.ts | 2 +- src/messages.ts | 2 ++ test/index.js | 4 +++- typings/messages.d.ts | 23 +++++++++++++++++++++++ 4 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 typings/messages.d.ts diff --git a/src/filesystem.ts b/src/filesystem.ts index 2cae939..3cf03e3 100644 --- a/src/filesystem.ts +++ b/src/filesystem.ts @@ -113,7 +113,7 @@ export class FSAssetStore { return resolve(asset) }) } else { - return reject(`Failed to download asset ${JSON.stringify(asset)}`) + return reject(messages.errors.assetDownloadFailed(asset)) } }) .catch(reject) diff --git a/src/messages.ts b/src/messages.ts index 1242816..4d2c59c 100644 --- a/src/messages.ts +++ b/src/messages.ts @@ -14,6 +14,8 @@ export const messages = { `The key '${key}' does not exist on: ${JSON.stringify(asset)}`, contentStoreLoadFailed: () => 'Failed to load content store:', + assetDownloadFailed: (asset: any) => + `Failed to download asset ${JSON.stringify(asset)}`, }, // Info/Debug messages diff --git a/test/index.js b/test/index.js index 72fe5ed..8067c01 100644 --- a/test/index.js +++ b/test/index.js @@ -8,6 +8,7 @@ const assetConnector = require('../dist') const config = require('../dist/config') const filesystem = require('fs') +const { messages } = require('../dist/messages') let connector = null let conf = { @@ -128,7 +129,8 @@ describe('# asset test', function () { test('# download non existent asset', function () { return connector.download(asset_data2).then(function () { }).catch(error =>{ - expect(error).toBe('blt9c4ef3c49f7b18h9 Asset download failed') + // Verify that download fails with correct error message + expect(error).toBe(messages.errors.assetDownloadFailed(asset_data2)) }) }) diff --git a/typings/messages.d.ts b/typings/messages.d.ts new file mode 100644 index 0000000..d0eff5e --- /dev/null +++ b/typings/messages.d.ts @@ -0,0 +1,23 @@ +/*! + * contentstack-sync-asset-store-filesystem + * copyright (c) Contentstack LLC + * MIT Licensed + */ + +export declare const messages: { + errors: { + keyNotExist: (key: string, asset: any) => string; + contentStoreLoadFailed: () => string; + assetDownloadFailed: (asset: any) => string; + }; + info: { + assetDownloadInitiated: (asset: any) => string; + assetDownloadFailed: (uid: string) => string; + assetDeletionInitiated: () => string; + assetFileRemovalError: (path: string) => string; + folderPathNotExist: (path: string) => string; + assetUnpublishInitiated: (asset: any) => string; + filePathNotExist: (path: string) => string; + }; +}; + From 680b9340fcec3ca196a6921086c397bddf4bd4d9 Mon Sep 17 00:00:00 2001 From: reeshika-h Date: Fri, 31 Oct 2025 15:11:16 +0530 Subject: [PATCH 4/5] chore: add typings/messages.d.ts to .talismanrc for improved type definitions --- .talismanrc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.talismanrc b/.talismanrc index 27d2ffe..962a75f 100644 --- a/.talismanrc +++ b/.talismanrc @@ -8,4 +8,6 @@ fileignoreconfig: checksum: 3563972e6fef958b021444c41ef04f5f32e83d1d51f7faea62ad1633130b6f1a - filename: src/messages.ts checksum: 5fc01b165e2fec0c969b954b15ab9201eaabcdce766c8b007907377f015f0043 +- filename: typings/messages.d.ts + checksum: f79568b5a95311acea1892c644554091c2b38d169a4867380693fa09e2639d95 version: "" From f0944f85f3113a95a7cc0a21d7d8e890dda213ad Mon Sep 17 00:00:00 2001 From: "harshitha.d" Date: Fri, 7 Nov 2025 17:27:44 +0530 Subject: [PATCH 5/5] chore: update version to 2.3.1 in package.json and package-lock.json --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4738bba..8901001 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@contentstack/datasync-asset-store-filesystem", - "version": "2.3.0", + "version": "2.3.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@contentstack/datasync-asset-store-filesystem", - "version": "2.3.0", + "version": "2.3.1", "license": "MIT", "dependencies": { "debug": "^4.3.4", diff --git a/package.json b/package.json index c527a92..247685e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@contentstack/datasync-asset-store-filesystem", - "version": "2.3.0", + "version": "2.3.1", "description": "Fillesystem asset store for DataSync libraries. Stores Contentstack asset-files in filesystem", "main": "./dist", "types": "./typings",