move code from clay.hpp to error.hpp