Fix bug not raising errors in certain cases