Skip to content

Commit c0b6be8

Browse files
author
jakub.pawlowski
committed
Eliminate the possibilty of invoking callback twice.
In a very specific case, when `callback` function passed to `getJson` would throw exception, it would be called again from inside `catch` clause.
1 parent 1a41d23 commit c0b6be8

File tree

1 file changed

+7
-3
lines changed
  • packages/oc-azure-storage-adapter

1 file changed

+7
-3
lines changed

packages/oc-azure-storage-adapter/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,16 @@ module.exports = function (conf) {
9191
return callback(err);
9292
}
9393

94+
let parsed = null;
9495
try {
95-
callback(null, JSON.parse(file));
96+
parsed = JSON.parse(file);
9697
} catch (er) {
9798
return callback({
9899
code: strings.errors.STORAGE.FILE_NOT_VALID_CODE,
99100
msg: format(strings.errors.STORAGE.FILE_NOT_VALID, filePath)
100101
});
101102
}
103+
callback(null, parsed);
102104
});
103105
};
104106

@@ -272,12 +274,14 @@ module.exports = function (conf) {
272274
};
273275

274276
const putFile = (filePath, fileName, isPrivate, callback) => {
277+
let stream = null;
275278
try {
276-
const stream = fs.createReadStream(filePath);
277-
return putFileContent(stream, fileName, isPrivate, callback);
279+
stream = fs.createReadStream(filePath);
278280
} catch (e) {
281+
console.log('putfile error!', e);
279282
return callback(e);
280283
}
284+
return putFileContent(stream, fileName, isPrivate, callback);
281285
};
282286

283287
return {

0 commit comments

Comments
 (0)