#How deep should i avoid nest error ?

5 messages · Page 1 of 1 (latest)

regal bane
#

this seems wrong. even after enrolling the user you still return and error? isn't that technically a success case?

#

you have 4 cases right now:

  1. you get the progress for a user and you give it back (happy path 1)
  2. there there is no learning progress for a user, you enroll them, and then return sql.ErrNoRows (shouldnt' you return like 0?)
  3. getting the progress fails for a different reason
  4. enrolling fails
#

currently you kind of merge 2 and 3

#

you probably want something like:

l, err := Progress(ctx, usr)
switch {
case errors.Is(er, sqlErrNoRows):
  if err := Enroll(ctx, usr); err != nil {
    return err
  }
  l = 0 // no progress
case err != nil:
  return err
}
crude lichen