return error if buf_size is too small