Skip to content

Commit 08fec35

Browse files
authored
Merge pull request #1474 from Duet3D/hotfix-filechecks
Updating file read.ts
2 parents ee99e99 + c7d701f commit 08fec35

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

nodescriptsTS/src/functions_platform_stats.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,9 @@ const getPlatformVersionPerRelease = async (browser_download_url) => {
9292
const getPluginPlatformVersionList = async (gituser, gitrepo, parent_folder = 'plugin_versions', is_new_plugin = false) => {
9393
let file_path = `${parent_folder}/${gitrepo}.json`;
9494
console.log("getPluginPlatformVersionList for", gituser, gitrepo, file_path, is_new_plugin)
95-
let current_file_temp = [];
96-
try{
97-
current_file_temp = is_new_plugin ? [] : await readFile.JSON(file_path);
98-
}
99-
catch(e){
100-
console.log("Error - Reading file ", file_path);
101-
console.log(e);
102-
}
10395

104-
const current_file = current_file_temp;
96+
const current_file = is_new_plugin ? [] : await readFile.JSON(file_path) || [];
97+
10598
const latest_tagName = ((current_file || [])[0] || {})['tagName'];
10699
const releases = await getReleases(gituser, gitrepo, latest_tagName) || [];
107100
console.log(gitrepo, ': New Releases');

nodescriptsTS/src/util.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,15 @@ const readFile = {
141141
return new Promise((resolve, reject) => {
142142
fs.readFile(path, (err, data) => {
143143
if (err) reject(err);
144-
resolve(JSON.parse((data||"{}").toString()));
144+
try{
145+
resolve(JSON.parse((data).toString()));
146+
}
147+
catch(e){
148+
console.log("Error readFile");
149+
console.log(e);
150+
resolve(false);
151+
}
152+
145153
});
146154
});
147155
},

0 commit comments

Comments
 (0)