#How deep should i avoid nest error ?
5 messages · Page 1 of 1 (latest)
you have 4 cases right now:
- you get the progress for a user and you give it back (happy path 1)
- there there is no learning progress for a user, you enroll them, and then return sql.ErrNoRows (shouldnt' you return like 0?)
- getting the progress fails for a different reason
- 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
}
i forgot to the 2, on err2; cause as you say enroll the error can failed for whatever reason