Check crash file exists before reading
Summary: File watcher gives deletion events as well, so this is needed to avoid attempting to read nonexistent files. We're getting ENOENT errors from this code, and I suspect this is the reason. Reviewed By: nikoant Differential Revision: D19329894 fbshipit-source-id: 46734ea17874e1448d67cc086b363e0abdf07258
This commit is contained in:
committed by
Facebook Github Bot
parent
8a136542a3
commit
7bdde77b36
@@ -34,6 +34,7 @@ import fs from 'fs';
|
|||||||
import os from 'os';
|
import os from 'os';
|
||||||
import util from 'util';
|
import util from 'util';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
import {promisify} from 'util';
|
||||||
import type {Notification} from '../../plugin.tsx';
|
import type {Notification} from '../../plugin.tsx';
|
||||||
import type {Store, DeviceLogEntry, OS, Props} from 'flipper';
|
import type {Store, DeviceLogEntry, OS, Props} from 'flipper';
|
||||||
import {Component} from 'react';
|
import {Component} from 'react';
|
||||||
@@ -372,7 +373,12 @@ function addFileWatcherForiOSCrashLogs(
|
|||||||
if (!filename || !checkFileExtension) {
|
if (!filename || !checkFileExtension) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fs.readFile(path.join(dir, filename), 'utf8', function(err, data) {
|
const filepath = path.join(dir, filename);
|
||||||
|
promisify(fs.exists)(filepath).then(exists => {
|
||||||
|
if (!exists) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fs.readFile(filepath, 'utf8', function(err, data) {
|
||||||
if (store.getState().connections.selectedDevice?.os != 'iOS') {
|
if (store.getState().connections.selectedDevice?.os != 'iOS') {
|
||||||
// If the selected device is not iOS don't show crash notifications
|
// If the selected device is not iOS don't show crash notifications
|
||||||
return;
|
return;
|
||||||
@@ -381,7 +387,12 @@ function addFileWatcherForiOSCrashLogs(
|
|||||||
console.error(err);
|
console.error(err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
parseCrashLogAndUpdateState(store, util.format(data), setPersistedState);
|
parseCrashLogAndUpdateState(
|
||||||
|
store,
|
||||||
|
util.format(data),
|
||||||
|
setPersistedState,
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user