Skip to content

Error handling in read function #3

Closed Answered by MarioCarrion
pantelis-karamolegkos asked this question in Q&A
Discussion options

You must be logged in to vote

Hello!

Great question and also it looks like I totally forgot to check other errors, thanks for calling that out.

I approach this in two different ways:

  • Return another channel for the error and use select together with the one for reading the values (errGroupWithErrChannel)
  • Define a new type that saves the err value and check that after the reading channel is closed (errGroupWithType)

Both implementations are here; to keep everything simple I'm only showing the example using errgroup, but using sync should be similar.

I typically start with the function and then depending if I need more details about the read process I implement the type one.

I hope that helps.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by MarioCarrion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #2 on December 19, 2021 21:38.