Skip to content

Commit c43c80b

Browse files
cwdickFacebook Github Bot 7
authored andcommitted
fix error handling in react native heap capture server middleware
Reviewed By: bnham Differential Revision: D3684092 fbshipit-source-id: 1856fa4c04a173e1df49dfe17ebef09a066447e5
1 parent e6b8508 commit c43c80b

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

local-cli/server/middleware/heapCaptureMiddleware.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,12 @@ module.exports = function(req, res, next) {
2525
fs.appendFileSync(preload, req.rawBody);
2626
fs.appendFileSync(preload, ';');
2727
res.end();
28+
const captureDir = path.join(__dirname, 'heapCapture/captures');
29+
if (!fs.existsSync(captureDir)) {
30+
fs.mkdirSync(captureDir);
31+
}
2832
console.log('Packaging Trace');
29-
var captureHtml = path.join(__dirname, 'heapCapture/captures/capture_' + Date.now() + '.html');
33+
var captureHtml = captureDir + '/capture_' + Date.now() + '.html';
3034
var capture = fs.createWriteStream(captureHtml);
3135
var inliner = spawn(
3236
'inliner',
@@ -35,6 +39,10 @@ module.exports = function(req, res, next) {
3539
stdio: [ process.stdin, 'pipe', process.stderr ],
3640
});
3741
inliner.stdout.pipe(capture);
42+
inliner.on('error', (err) => {
43+
console.error('Error processing heap capture: ' + err.message);
44+
console.error('make sure you have installed inliner with \'npm install inliner -g\'');
45+
});
3846
inliner.on('exit', (code, signal) => {
3947
if (code === 0) {
4048
console.log('Heap capture written to: ' + captureHtml);

0 commit comments

Comments
 (0)