Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

Commit 6dc14c3

Browse files
author
Mark Wolff
authored
fix: do not throw when no dir (#48)
1 parent 13328b9 commit 6dc14c3

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

packages/azure-opentelemetry-exporter/src/platform/nodejs/persist/fileSystemPersist.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ export class FileSystemPersist implements PersistentStorage {
5959

6060
fs.stat(tempDir, (statErr: Error | null, stats: fs.Stats) => {
6161
if (statErr) {
62-
callback(statErr);
62+
if (((statErr as unknown) as { code: string }).code === 'ENOENT') {
63+
callback(null);
64+
} else {
65+
callback(statErr);
66+
}
6367
} else if (stats.isDirectory()) {
6468
fs.readdir(tempDir, (error, origFiles) => {
6569
if (!error) {

packages/azure-opentelemetry-exporter/test/platform/nodejs/persist/fileSystemPersist.test.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,24 @@ describe('FileSystemPersist', () => {
9494
});
9595

9696
describe('#shift()', () => {
97+
it('should not crash if folder does not exist', (done) => {
98+
const persister = new FileSystemPersist({ instrumentationKey });
99+
persister.shift((err) => {
100+
assert.strictEqual(err, null);
101+
done();
102+
});
103+
});
104+
97105
it('should not crash if file does not exist', (done) => {
98106
const persister = new FileSystemPersist({ instrumentationKey });
99-
assert.doesNotThrow(() => {
107+
fs.mkdir(tempDir, () => {
100108
persister.shift((err) => {
101-
assert.ok(err);
109+
assert.strictEqual(err, null);
102110
done();
103111
});
104112
});
105113
});
114+
106115
it('should get the first file on disk and return it', (done) => {
107116
const persister = new FileSystemPersist({ instrumentationKey });
108117

0 commit comments

Comments
 (0)