Permalink
Browse files

fix error handling in react native heap capture server middleware

Reviewed By: bnham

Differential Revision: D3684092

fbshipit-source-id: 1856fa4c04a173e1df49dfe17ebef09a066447e5
  • Loading branch information...
1 parent e6b8508 commit c43c80bd7c91edfb983d640906e7a5805f9ab8fd @cwdick cwdick committed with Facebook Github Bot 7 Aug 9, 2016
Showing with 9 additions and 1 deletion.
  1. +9 −1 local-cli/server/middleware/heapCaptureMiddleware.js
@@ -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);

0 comments on commit c43c80b

Please sign in to comment.