core: Split out error enum handling into sharable trait.