Skip to content
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

Wrap error to allow for better error handling #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gcangussu
Copy link

Wrapping the error properly allows for real world use cases. On our case we want to add new fields to the struct and keep compatibility with the data encoded in the past.

func (data *Data) UnmarshalEnkodo(dec *enkodo.Decoder) error {
  var err error
  
  if data.OldField, err = dec.String(); err != nil {
    return err
  }

  if data.NewField, err = dec.String(); err != nil {
    if errors.Is(err, io.EOF) {
      return nil // ok, data was encoded without new field
    }
    return err
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant