Skip to content

Commit

Permalink
Catch corrupted json messages, likely due to premature flush in scann…
Browse files Browse the repository at this point in the history
…er script
  • Loading branch information
dcyoung committed May 16, 2017
1 parent ceb5e4b commit 2295da1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 8 additions & 1 deletion routes/component_testing.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,14 @@ function performTest(params) {
// Handle normal output
scriptExecution.stdout.on('data', (data) => {
console.log(uint8arrayToString(data));
let jsonObj = JSON.parse(uint8arrayToString(data));
let jsonObj = null;
try {
jsonObj = JSON.parse(uint8arrayToString(data));
}
catch (e) {
console.log(e);
return;
}
console.log(jsonObj);

// Store the update as the current status
Expand Down
9 changes: 8 additions & 1 deletion routes/scan.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,14 @@ function performScan(params) {

// Handle normal output
scriptExecution.stdout.on('data', (data) => {
let jsonObj = JSON.parse(uint8arrayToString(data));
let jsonObj = null;
try {
jsonObj = JSON.parse(uint8arrayToString(data));
}
catch (e) {
console.log(e);
return;
}
console.log(jsonObj);

// Store the update as the current status
Expand Down

0 comments on commit 2295da1

Please sign in to comment.