Skip to content

Conversation

@lorenyu
Copy link
Contributor

@lorenyu lorenyu commented Mar 13, 2019

Context

In ghostscript4js, whenever the gs command returns a nonzero exit code it triggers a fatal unrecoverable error that can't be handled in JavaScript. In particular, the GhostscriptManager class tries to throw a char* exception and the GhostscriptWorker (subclass of Napi::AsyncWorker) tries to catch it to set the JavaScript error with SetError. While I'm not deeply familiar with Napi, I've found that if we throw a std::string exception instead and change SetError to set the string of the exception rather than use Napi::String::New, we can properly handle the error in JavaScript.

Changes

  • Change GhostscriptManager to throw string instead of char*
  • Change SetError call to set exception string

Incidental change

  • Fix test to not hardcode ghostscript version to 2017

Testing

  • Tested in uploads-processor app, a separate project I'm working on.
  • Ran npm test

@lorenyu lorenyu closed this Mar 13, 2019
@NickNaso
Copy link
Owner

Hi @lorenyu I saw the PR only now. Why did you close it?

@lorenyu
Copy link
Contributor Author

lorenyu commented Mar 15, 2019

@NickNaso sorry that was a misfire. I hadn't finished with it yet, wanted to add a unit test to cover the case. I put up a new PR with the same fix and the unit test #41, can you review that one? Thanks!

@NickNaso
Copy link
Owner

NickNaso commented Mar 15, 2019

@lorenyu I'm very happy about your contribution. When you will end the work open a new PR and I will review it.

@lorenyu
Copy link
Contributor Author

lorenyu commented Mar 15, 2019

@NickNaso happy to contribute! I finished the work and opened up PR #41, let me know if there is anything else you need from me there. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants