modified stream to return error code