public function addError(Error $error) { // create a local copy of the error stack $errors = $this->errors; // append the error to the stack $errors[] = $error; // copy the error stack back to the thread context $this->errors = $errors; }