fix error handling in react native heap capture server middleware

Reviewed By: bnham

Differential Revision: D3684092

fbshipit-source-id: 1856fa4c04a173e1df49dfe17ebef09a066447e5
This commit is contained in:
Charles Dick 2016-08-09 04:26:41 -07:00 коммит произвёл Facebook Github Bot 7
Родитель e6b850871b
Коммит c43c80bd7c
1 изменённых файлов: 9 добавлений и 1 удалений

Просмотреть файл

@ -25,8 +25,12 @@ module.exports = function(req, res, next) {
fs.appendFileSync(preload, req.rawBody);
fs.appendFileSync(preload, ';');
res.end();
const captureDir = path.join(__dirname, 'heapCapture/captures');
if (!fs.existsSync(captureDir)) {
fs.mkdirSync(captureDir);
}
console.log('Packaging Trace');
var captureHtml = path.join(__dirname, 'heapCapture/captures/capture_' + Date.now() + '.html');
var captureHtml = captureDir + '/capture_' + Date.now() + '.html';
var capture = fs.createWriteStream(captureHtml);
var inliner = spawn(
'inliner',
@ -35,6 +39,10 @@ module.exports = function(req, res, next) {
stdio: [ process.stdin, 'pipe', process.stderr ],
});
inliner.stdout.pipe(capture);
inliner.on('error', (err) => {
console.error('Error processing heap capture: ' + err.message);
console.error('make sure you have installed inliner with \'npm install inliner -g\'');
});
inliner.on('exit', (code, signal) => {
if (code === 0) {
console.log('Heap capture written to: ' + captureHtml);