-
Notifications
You must be signed in to change notification settings - Fork 4
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
[feature] export types #41
Conversation
|
||
export async function getEngines(deps: Array<string>, manager: Manager): Promise<EnginesDataArray> { | ||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think we should probably keep this try/catch
because the Promise.all
in getYarnEngines
could throw, which I believe would cause an Unhandled Promise Rejection
without it.
there's a try/catch
in readJsonFile
-- if it throws an unexpected error, it would cause Promise.all
to reject and it isn't being caught at the call site. I don't think rejections like this (Promises across functions) bubble up to the next highest catch
block, but I'm not positive.
or, alternatively, we could put a try/catch
around the code in getYarnEngines
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
after reading more, i think the right move is putting the try/catch
around the code in getYarnEngines
@@ -24,10 +24,7 @@ export async function execWithLog<T>(text: string, callback: () => Promise<T>) { | |||
} | |||
}, 200); | |||
try { | |||
const output = await callback(); | |||
return output; | |||
} catch (error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same thing here, i think -- callback
could technically be any async
function -- if it's a Promise that can reject, this would lead to an Unhandled Promise Rejection
I got your points to keep the } catch (error) {
throw error;
} So, should we do something specific in these |
@KostiantynPopovych in some of them we should (and we do, when we know certain errors won't lead to unexpected behavior. like if but for others, i think it makes sense to throw the error so it bubbles up to the function it's being called in. not to mention, i tend to take an "err on the side of caution" approach when it comes to error handling. i also don't think it hurts to have i guess that's my plan for these that just re-throw -- we know, at the very least, the error will reach the top-level however, i do think my |
I agree that catch and only re-throw the error is not that useful, errors already go up the call stack anyway so this is adding extra try/catch overhead, I would vote to remove those too I do see the reason behind being explicit like "I know this can throw an exception" because this is a big issue with JavaScript in general and there's no simple way to fix it, but I don't know if adding a try/catch is the best solution (I think it's something the language should fix, or maybe a function name convention like in rails a method with |
well for in in besides those cases -- i think re-throwing is valuable for debugging purposes. when we re-throw, the stack trace gets thrown along with it. so when it's finally logged, the trace starts at the actual function that threw originally, instead of the function that the error bubbled up to (even if the error originated in one of our dependencies). as far as overhead is concerned -- i think that might be an (unnecessary?) optimization at the expense of easier debugging. and, since we're no longer fetching from plus, it looks like we're only re-throwing in 5 places -- the 3 I mentioned above, |
but if you re-throw an error you still have to handle it catching it somewhere else, right? I'm missing why the re-throw is needed since exceptions already bubble up the stack and you can always catch them when you want to deal with them and you can debug things the same way for maybe I don't see the exact use case where a re-throw is better for debugging than just letting the exception go up normally, one could argue that having the complete stack trace from the original call is better than having the stack trace starting where you re-threw it, at least for me more information of an error is better (or I'm seeing this backwards?) EDIT: I don't want this to take forever to be discussed though, I just think that over-pessimistic (worrying about unexpected errors) code is a bad pattern, everything can fail at some point so we would need try/catch just in cases in a lot of places |
they don't always bubble up the stack -- re-throwing does preserve the original call site. it's if we did something like also, i read some more and i think i misunderstood how stack traces are built in Node. so most of my original argument (besides and also also -- yeah, this conversation doesn't have to drag out. I just miss learning and BSing with you guys and it's so much faster in Slack lol. So to speed this up, what if:
|
Hey @arielj @kindoflew, I reverted the logic of catching promises, but I also changed the build method in favor of using tsup. This migration reduced the amount of build-related dev dependencies to two - Also, I just tried to run builded version of the |
works for me! i'm not married to as far as changing our |
This PR fixes WebStorm's eslint resolution error, adds types into the
dist
folder for further import & usage ofdepngn
as a function, and fixes eslint errors throughout the project.