Repository navigation
Make Nan::ThrowError calls consistent and clean up when errors are thrown - #103
Conversation
Ryan Prichard (rprichard)
left a comment
There was a problem hiding this comment.
I'm traveling, so I looked it over quickly. It basically looked OK to me. I noticed a few things that may need fixing.
| std::stringstream why; | ||
| std::wstring msg(winpty_error_msg(error_ptr)); | ||
| std::string msg_(msg.begin(), msg.end()); | ||
| std::string generalMsg_(generalMsg); |
There was a problem hiding this comment.
It looks like generalMsg_ is unused?
| void throw_winpty_error(const char *generalMsg, winpty_error_ptr_t error_ptr) { | ||
| std::stringstream why; | ||
| std::wstring msg(winpty_error_msg(error_ptr)); | ||
| std::string msg_(msg.begin(), msg.end()); |
There was a problem hiding this comment.
I'm not 100% sure, but I think the initializer of msg_ converts the wide string to a narrow string by truncating each wchar_t value to a char. It will only be correct for ASCII characters. I'm guessing node.js and/or v8 want UTF-8 strings? Standard C++ has a way to do that conversion (as of C++11, I think -- I'm thinking of std::codecvt), and maybe node.js / v8 also does? Windows has C-style APIs to do the conversion.
I think the pattern already existed in the code, so it's probably not necessary to fix it in this PR? e.g. see shellpath_'s initializer.
There was a problem hiding this comment.
Thanks for the feedback, tracking in #104 🙂
| throw_winpty_error("Error creating WinPTY config", error_ptr); | ||
| goto cleanup; | ||
| } | ||
| winpty_error_free(error_ptr); |
There was a problem hiding this comment.
I think the code leaks error objects when an error occurs. Should there should be another winpty_error_free call for the cleanup label? (If you add one, make sure you don't call winpty_error_free twice on the same non-nullptr value -- that would cause a double-free crash. Maybe set error_ptr to nullptr after each free call.)
The other calls could be removed, in practice, because each winpty API either:
- succeeds, and sets *error_ptr to nullptr, OR
- fails, and sets *error_ptr to an error object.
Calling winpty_error_free on nullptr has no effect. I'm not sure whether the best convention is to always call winpty_error_free after each API call, or whether to only call it after detecting an error.
Make Nan::ThrowError calls consistent and clean up when errors are thrown
When winpty exceptions occurred they were silently failing due to marshal not being initialized. Part of microsoft#102 Part of microsoft#103
Fixes #102
Ryan Prichard (@rprichard) if you can a quick review would be awesome