Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error Handling if Pdf path is not Found #25

Open
janschmutz opened this issue Sep 6, 2017 · 6 comments
Open

Error Handling if Pdf path is not Found #25

janschmutz opened this issue Sep 6, 2017 · 6 comments
Labels

Comments

@janschmutz
Copy link

Hi, how can I handle Errors, if the Pdf Input Path was not found?. I'd like to use the 'error' event, to handle the error. But instead it throws me this error:

'throw er; // Unhandled stream error in pipe.'

@janschmutz
Copy link
Author

janschmutz commented Sep 6, 2017

function createPdfCollection (sticker) {
var out = 'out.pdf';
var in = 'in.pdf';
var pdf = scissors(in)
    .pages(sticker)
    .pdfStream()
    .pipe(fs.createWriteStream(out))
    .on('finish', function(){
        console.log("Created new Pdf");
    })
    .on('error',function(err){
        console.log('Handle this: ' + err)
    });
}

@cboulanger
Copy link
Collaborator

@janschmutz Thanks for the report.

@tcr : in https://github.com/tcr/scissors/blob/master/scissors.js#L118 seqq., I see that errors thrown by non-existing files will be caught and ignored (it returns this.input). Why is that?

@cboulanger cboulanger self-assigned this Sep 6, 2017
@cboulanger cboulanger added the bug label Sep 6, 2017
@janschmutz
Copy link
Author

janschmutz commented Sep 6, 2017

Thank you,
also as you can see I'm passing a array of pages as arguments, this works.
However calling pdf.pages.apply(pdf, args); doesn't.
Es6 Spread pdf.pages(...args) works.
might be worth a notice in the documentation

@janschmutz
Copy link
Author

Any updates on this issue?

@cboulanger
Copy link
Collaborator

@tcr, in case you didn't see the question before - can you have a quick look, would make things easier to solve: in https://github.com/tcr/scissors/blob/master/scissors.js#L118 seqq., I see that errors thrown by non-existing files will be caught and ignored (it returns this.input). Why is that?

@tcr
Copy link
Owner

tcr commented Oct 22, 2017

My best guess at what this code was doing (and this might be just a guess) was the following:

  1. Expand a relative filename argument to an absolute path, because some PDF programs (which?) required absolute paths. It may have been that they wrote output files relative to the first argument, rather than the current directory.
  2. Some programs need to create a temporary intermediate file, which doesn't exist when the script is first executed. This temporary intermediate file will always be an absolute path; thus we don't need to do the "fixing" step in step 1 for any reason, and can swallow its error.
  3. If the filename doesn't exist, we assume it will be created in the middle of program execution at some point. So just return it.

If I'm correct about the above, an easy fix would be to change the function signature to _input(suppressNonexisting: boolean). suppressNonexisting would be true for a Command which has had another stream piped to it. It would be false otherwise, which means the first Command checks whether the filename exists; the rest just assume it does.

@cboulanger cboulanger removed their assignment Mar 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants