Heroku PDFTK выбрасывает неопределенную ошибку EPIPE и EACCES - PullRequest
0 голосов
/ 16 января 2020

У меня есть приложение на веб-диджоне heroku hobby, использующее довольно базовый c интерфейс API. У нас есть ряд PDF-файлов, которые прикрепляются к PDF-файлам, генерируемым кукловодом. Мой код работает, когда я запускаю его локально (windows), но он также работает и при развертывании на моем производственном экземпляре heroku. Вот код проблемы c:

try{

//If there are pdfs to attach to the end of the file, we do it here.
let fileList = [];
console.log('*');
for (const file of pdfFileNameList) {
    fileList.push("./pdfs/" + file.pdf);
}

console.log('**');
//Spawn a child process to run pdftk to merge the pdfs.
let execer = require('child_process').spawn;
let child;
let args = ['-'].concat(fileList).concat(['cat', 'output', '-']);
console.log(args);

console.log('***');
child = execer('pdftk', args, {
    encoding: 'binary',
    stdio: ['pipe']
});

//Write the file PDF binary data to the child process' stdin.
//It will combine that with the list of pdfs specified in fileList.
console.log('****');
child.stdin.write(data);
console.log('*****');
child.stdin.end();
console.log('******');

let bufferArray = [];
//shove the data from the child process into my bufferArray as it comes in.
child.stdout.on('data', function (pdfdata) {
    bufferArray.push(new Buffer(pdfdata, 'binary'));
});
console.log('*******');
//When the process is done, send the concatted pdf to the user.
child.on('close', function () {
    res.header('Content-Type', "application/pdf");
    res.send(Buffer.concat(bufferArray));
});
console.log('********');

} catch (err) {
    console.error(err);
}

А вот результирующий набор ошибок:

2020-01-16T18:02:37.830775+00:00 app[web.1]: *
2020-01-16T18:02:38.356266+00:00 app[web.1]: **
2020-01-16T18:02:38.358310+00:00 app[web.1]: [ '-', '/app/pdfs/Example.pdf', 'cat', 'output', '-' ]
2020-01-16T18:02:38.358371+00:00 app[web.1]: ***
2020-01-16T18:02:38.373374+00:00 app[web.1]: ****
2020-01-16T18:02:38.375832+00:00 app[web.1]: Error: write EPIPE
2020-01-16T18:02:38.375836+00:00 app[web.1]: at afterWriteDispatched (internal/stream_base_commons.js:149:25)
2020-01-16T18:02:38.375838+00:00 app[web.1]: at writeGeneric (internal/stream_base_commons.js:140:3)
2020-01-16T18:02:38.375843+00:00 app[web.1]: at Socket._writeGeneric (net.js:776:11)
2020-01-16T18:02:38.375845+00:00 app[web.1]: at Socket._write (net.js:788:8)
2020-01-16T18:02:38.375847+00:00 app[web.1]: at doWrite (_stream_writable.js:435:12)
2020-01-16T18:02:38.375849+00:00 app[web.1]: at writeOrBuffer (_stream_writable.js:419:5)
2020-01-16T18:02:38.375851+00:00 app[web.1]: at Socket.Writable.write (_stream_writable.js:309:11)
2020-01-16T18:02:38.375853+00:00 app[web.1]: at Object.returnReport (/app/models/report_functions.js:245:33) {
2020-01-16T18:02:38.375855+00:00 app[web.1]: errno: 'EPIPE',
2020-01-16T18:02:38.375857+00:00 app[web.1]: code: 'EPIPE',
2020-01-16T18:02:38.375859+00:00 app[web.1]: syscall: 'write'
2020-01-16T18:02:38.375861+00:00 app[web.1]: }
2020-01-16T18:02:38.378481+00:00 app[web.1]: events.js:200
2020-01-16T18:02:38.378484+00:00 app[web.1]: throw er; // Unhandled 'error' event
2020-01-16T18:02:38.378486+00:00 app[web.1]: ^
2020-01-16T18:02:38.378488+00:00 app[web.1]:
2020-01-16T18:02:38.378490+00:00 app[web.1]: Error: spawn pdftk EACCES
2020-01-16T18:02:38.378492+00:00 app[web.1]: at Process.ChildProcess._handle.onexit (internal/child_process.js:264:19)
2020-01-16T18:02:38.378495+00:00 app[web.1]: at onErrorNT (internal/child_process.js:456:16)
2020-01-16T18:02:38.378497+00:00 app[web.1]: at processTicksAndRejections (internal/process/task_queues.js:81:21)
2020-01-16T18:02:38.378499+00:00 app[web.1]: Emitted 'error' event on ChildProcess instance at:
2020-01-16T18:02:38.378501+00:00 app[web.1]: at Process.ChildProcess._handle.onexit (internal/child_process.js:270:12)
2020-01-16T18:02:38.378503+00:00 app[web.1]: at onErrorNT (internal/child_process.js:456:16)
2020-01-16T18:02:38.378505+00:00 app[web.1]: at processTicksAndRejections (internal/process/task_queues.js:81:21) {
2020-01-16T18:02:38.378507+00:00 app[web.1]: errno: 'EACCES',
2020-01-16T18:02:38.378509+00:00 app[web.1]: code: 'EACCES',
2020-01-16T18:02:38.378511+00:00 app[web.1]: syscall: 'spawn pdftk',
2020-01-16T18:02:38.378513+00:00 app[web.1]: path: 'pdftk',
2020-01-16T18:02:38.378515+00:00 app[web.1]: spawnargs: [ '-', '/app/pdfs/Example.pdf', 'cat', 'output', '-' ]
2020-01-16T18:02:38.378517+00:00 app[web.1]: }
...