@itentialopensource/adapter-kafkav2 0.16.0 → 0.16.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,4 +1,12 @@
1
1
 
2
+ ## 0.16.1 [08-24-2023]
3
+
4
+ * Handle empty topics file
5
+
6
+ See merge request itentialopensource/adapters/notification-messaging/adapter-kafkav2!13
7
+
8
+ ---
9
+
2
10
  ## 0.16.0 [08-23-2023]
3
11
 
4
12
  * Add logic to clean topics.json from service config
package/adapter.js CHANGED
@@ -181,13 +181,31 @@ class Kafkav2 extends AdapterBaseCl {
181
181
  this.topicsEvents = [];
182
182
  let topicsFile = path.join(__dirname, `/.topics-${this.id}.json`);
183
183
 
184
- // if the file does not exist - error
184
+ // Check if the file exists
185
185
  if (fs.existsSync(topicsFile)) {
186
- this.topicsEvents = JSON.parse(fs.readFileSync(topicsFile, 'utf-8'));
186
+ const fileContent = fs.readFileSync(topicsFile, 'utf-8');
187
+
188
+ // Check if the file is empty
189
+ if (fileContent.trim() === '') {
190
+ // If it's empty, write an empty array to the file
191
+ fs.writeFileSync(topicsFile, '[]');
192
+ } else {
193
+ // Parse the existing content
194
+ this.topicsEvents = JSON.parse(fileContent);
195
+ }
187
196
  } else if (fs.existsSync(path.join(__dirname, '/.topics.json'))) {
188
197
  log.debug('Found old .topics.json file.');
189
198
  topicsFile = path.join(__dirname, '/.topics.json');
190
- this.topicsEvents = JSON.parse(fs.readFileSync(topicsFile, 'utf-8'));
199
+ const fileContent = fs.readFileSync(topicsFile, 'utf-8');
200
+
201
+ // Check if the file is empty
202
+ if (fileContent.trim() === '') {
203
+ // If it's empty, write an empty array to the file
204
+ fs.writeFileSync(topicsFile, '[]');
205
+ } else {
206
+ // Parse the existing content
207
+ this.topicsEvents = JSON.parse(fileContent);
208
+ }
191
209
  }
192
210
 
193
211
  // get the topics into the right format --- fix older .topics.json files so they have the right format
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itentialopensource/adapter-kafkav2",
3
- "version": "0.16.0",
3
+ "version": "0.16.1",
4
4
  "description": "Itential adapter to connect to kafka",
5
5
  "main": "adapter.js",
6
6
  "wizardVersion": "2.35.0",
Binary file