Skip to content

Commit

Permalink
File write error handling (microsoft#1024)
Browse files Browse the repository at this point in the history
  • Loading branch information
hectorhdzg authored Oct 24, 2022
1 parent 4c65638 commit 9c9e0b3
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions Library/Sender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,15 +414,22 @@ class Sender {
this._logWarn("Not saving data due to max size limit being met. Directory size in bytes is: " + size);
return;
}
//create file - file name for now is the timestamp, a better approach would be a UUID but that
}
catch (ex) {
this._logWarn("Failed to read directory for retriable telemetry: " + Util.dumpObj(ex));
this._onErrorHelper(ex);
return;
}
try {
//create file - file name for now is the timestamp, a better approach would be a UUID but that
//would require an external dependency
var fileName = new Date().getTime() + ".ai.json";
var fileFullPath = path.join(this._tempDir, fileName);

// Mode 600 is w/r for creator and no read access for others (only applies on *nix)
// For Windows, ACL rules are applied to the entire directory (see logic in _confirmDirExists and _applyACLRules)
this._logInfo("saving data to disk at: " + fileFullPath);
FileSystemHelper.writeFileAsync(fileFullPath, Util.stringify(envelopes), { mode: 0o600 });
await FileSystemHelper.writeFileAsync(fileFullPath, Util.stringify(envelopes), { mode: 0o600 });
}
catch (ex) {
this._logWarn("Failed to persist telemetry to disk: " + Util.dumpObj(ex));
Expand Down

0 comments on commit 9c9e0b3

Please sign in to comment.