unix: replace some asserts with returning errors