Skip to content

Commit f0e9045

Browse files
Merge pull request #62 from contentstack/feat/DX-3457-improve-error-msgs
updated error messages
2 parents ada777c + a10a21a commit f0e9045

File tree

4 files changed

+51
-10
lines changed

4 files changed

+51
-10
lines changed

clean.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const path = require("path");
44
const rimraf = require("rimraf");
55
const config = require("./config/all");
66
const { merge } = require("lodash");
7+
const messages = require("./messages");
78

89
// Set application's environment
910
const env = process.env.NODE_ENV || config.environment || "development";
@@ -28,8 +29,8 @@ pathsToDelete.forEach((fileOrDir) => {
2829
const fullPath = path.join(__dirname, fileOrDir);
2930
if (fs.existsSync(fullPath)) {
3031
rimraf.sync(fullPath);
31-
console.log("Deleted:", fileOrDir);
32+
console.log(messages.clean.deleted(fileOrDir));
3233
} else {
33-
console.log("Not found (skipped):", fileOrDir);
34+
console.log(messages.clean.notFound(fileOrDir));
3435
}
3536
});

index.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const path = require("path");
33
const _ = require("lodash");
44
const datasyncManager = require("@contentstack/datasync-manager");
55
const config = require("./config/all");
6+
const messages = require("./messages");
67
/**
78
* Listener module. Currently Contentstack offers
89
* - @contentstack/webhook-listener
@@ -37,9 +38,9 @@ if (appConfig.checkpoint?.enabled) {
3738
const checkpointPath = path.join(__dirname, appConfig.checkpoint.filePath || ".checkpoint");
3839
const checkPoint = readHiddenFile(checkpointPath);
3940
if (checkPoint) {
40-
console.log("Found sync token in checkpoint file:", checkPoint);
41+
console.log(messages.sync.tokenFound(checkPoint));
4142
appConfig.contentstack.sync_token = checkPoint.token;
42-
console.log("Using sync token:", appConfig.contentstack.sync_token);
43+
console.log(messages.sync.usingToken(appConfig.contentstack.sync_token));
4344
}
4445
}
4546

@@ -51,21 +52,21 @@ datasyncManager.setListener(listener);
5152
datasyncManager
5253
.start()
5354
.then(() => {
54-
console.log("Boilerplate: DataSync started successfully!");
55+
console.log(messages.sync.startSuccess());
5556
})
5657
.catch((error) => {
57-
console.error(error);
58+
console.error(messages.sync.error(error));
5859
});
5960

6061
function readHiddenFile(filePath) {
6162
try {
6263
if (!fs.existsSync(filePath)) {
63-
console.error("File does not exist:", filePath);
64+
console.error(messages.file.notExist(filePath));
6465
return;
6566
}
6667
const data = fs.readFileSync(filePath, "utf8");
6768
return JSON.parse(data);
6869
} catch (err) {
69-
console.error("Error reading file:", err?.message);
70+
console.error(messages.file.readError(err?.message));
7071
}
7172
}

messages.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Centralized message store for datasync-boilerplate
3+
* This file contains all user-facing messages including info, error, and warning messages.
4+
*/
5+
6+
module.exports = {
7+
// Clean script messages
8+
clean: {
9+
deleted: (item) => `Deleted: ${item}`,
10+
notFound: (item) => `Item not found! Skipping: ${item}`,
11+
},
12+
13+
// Index/Main application messages
14+
sync: {
15+
tokenFound: (checkpoint) => `Sync token found in the checkpoint file: ${JSON.stringify(checkpoint)}`,
16+
usingToken: (token) => `Using sync token: ${token}`,
17+
startSuccess: () => `Boilerplate: Data sync started successfully.`,
18+
error: (error) => `An error occurred: ${error}`,
19+
},
20+
21+
// File operation messages
22+
file: {
23+
notExist: (filePath) => `File does not exist: ${filePath}`,
24+
readError: (errorMessage) => `An error occurred while reading the file: ${errorMessage}`,
25+
},
26+
27+
// Plugin messages
28+
plugin: {
29+
itemLogger: {
30+
beforeSync: (action, uid, contentType) =>
31+
`Item logger - Before sync: ${action.toUpperCase()} operation on '${uid}' (content type: ${contentType})`,
32+
afterSync: (action, uid, contentType) =>
33+
`Item logger - After sync: ${action.toUpperCase()} operation on '${uid}' (content type: ${contentType})`,
34+
},
35+
},
36+
};
37+

plugins/item-logger/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1+
const messages = require('../../messages');
2+
13
module.exports = function Plugins () {
24
// eslint-disable-next-line no-unused-vars
35
const options = Plugins.options
46
const log = options.log
57

68
// eslint-disable-next-line no-unused-vars
79
Plugins.beforeSync = function (action, data, schema) {
8-
log(`item-logger before-sync logging: ${action.toUpperCase()} on ${data.uid} of ${data._content_type_uid}`)
10+
log(messages.plugin.itemLogger.beforeSync(action, data.uid, data._content_type_uid))
911
return Promise.resolve()
1012
}
1113

1214
// eslint-disable-next-line no-unused-vars
1315
Plugins.afterSync = function (action, data, schema) {
14-
log(`item-logger after-sync logging: ${action.toUpperCase()} on ${data.uid} of ${data._content_type_uid}`)
16+
log(messages.plugin.itemLogger.afterSync(action, data.uid, data._content_type_uid))
1517
return Promise.resolve()
1618
}
1719
}

0 commit comments

Comments
 (0)