<p>Is it obvious why the task validation errors are not getting output in my log:</p>

<pre><code>public function runStep($step)
{
    try
    {
        $entry = craft()-&gt;entries-&gt;getEntryById($this-&gt;_entryIds[$step], $this-&gt;_localeId);

        if (!$entry)
        {
            return true;
        }

        $newExpiryDate = new DateTime($entry-&gt;date);
        $newExpiryDate-&gt;add(new DateInterval('P1D'));


        // Update Expiry Date
        if($entry-&gt;expiryDate != $newExpiryDate)
        {
            $entry-&gt;expiryDate = $newExpiryDate-&gt;format('Y-m-d');
        }

        // Update Status
        $entry-&gt;enabled = true;

        // Save Entry
        if(craft()-&gt;entries-&gt;saveEntry($entry))
        {
            return true;    
        }
        else
        {
            $error = 'Encountered the following validation errors when trying to save entry with the ID "'.$entry-&gt;id.'":';

            foreach ($entry-&gt;getAllErrors() as $attributeError)
            {
                $error .= "\n - {$attributeError}";
            }

            return $error;              
        }

        return true;
    }
    catch (\Exception $e)
    {
        return 'An exception was thrown while trying to save the entry with the ID “'.$this-&gt;_entryIds[$step].'”: '.$e-&gt;getMessage();
    }
}
</code></pre>

<p>This task step is based on one of the Craft default steps but the error gets output without the specific validation issues:</p>

<blockquote>
  <p>Encountered an error running task 1191 (Logic_UpdateEvents), step 1 of 1440: Encountered the following validation errors when trying to save entry with the ID "10295":</p>
</blockquote>

CC BY-SA 3.0
2015-04-30T14:52:59.480Z
What happens if you `Craft::log('error count = '.count($entry->getAllErrors()));`
Brad Bell
CC BY-SA 3.0
2015-04-30T14:57:23.573Z
`error count = 1`
Sam Hibberd
CC BY-SA 3.0
2015-04-30T15:16:44.357Z
Looks O.K. to me.  What if you do: `Craft::log('error = '.$entry->getAllErrors[0]);`?
Brad Bell
CC BY-SA 3.0
2015-04-30T15:20:12.217Z
`Encountered an error running task 1193 (Logic_UpdateEvents), step 1 of 1440: An exception was thrown while trying to save the entry with the ID “10295”: Property "Craft\EntryModel.getAllErrors" is not defined.`
Sam Hibberd
CC BY-SA 3.0
2015-04-30T15:21:17.917Z
Wait a second surely that needs to be `Craft::log('error = '.$entry->getAllErrors()[0])` ?
Sam Hibberd
CC BY-SA 3.0
2015-04-30T15:22:59.483Z
That returns the error correctly!
Sam Hibberd
CC BY-SA 3.0
2015-04-30T21:12:33.267Z
Any idea what caused the issue with the existing code?
Sam Hibberd
CC BY-SA 3.0
2015-05-01T07:19:04.003Z
I've tested a few variations but the line which is pumping out the errors `$error .= "\n - {$attributeError}";` is not happy with \n PHP_EOL, it would be great to know how to get line breaks output into the logs and awesome to get this fixed in the craft core versions.
Sam Hibberd
CC BY-SA 3.0
2015-05-01T17:33:58.383Z
Try using `PHP_EOL` instead of `\n`.
Brad Bell
CC BY-SA 3.0
2015-05-01T17:34:47.257Z
Already tried. No go. :(
Sam Hibberd
CC BY-SA 3.0
2015-05-13T08:00:32.630Z
@BradBell Ive discovered that this exact task works as expected when Dev Mode is off! not sure if that helps explain anything??
Sam Hibberd
CC BY-SA 3.0
2015-05-13T14:29:42.513Z
That's really weird!
Brad Bell
<plugin-development><tasks><debugging>
Debugging Validation Errors In Craft
# Debugging Validation Errors In Craft

(Asked by: username_0 on 2015-04-30)

Is it obvious why the task validation errors are not getting output in my log:
public function runStep($step)
{
    try
    {
        $entry = craft()->entries->getEntryById($this->_entryIds[$step], $this->_localeId);

        if (!$entry)
        {
            return true;
        }

        $newExpiryDate = new DateTime($entry->date);
        $newExpiryDate->add(new DateInterval('P1D'));


        // Update Expiry Date
        if($entry->expiryDate != $newExpiryDate)
        {
            $entry->expiryDate = $newExpiryDate->format('Y-m-d');
        }

        // Update Status
        $entry->enabled = true;

        // Save Entry
        if(craft()->entries->saveEntry($entry))
        {
            return true;    
        }
        else
        {
            $error = 'Encountered the following validation errors when trying to save entry with the ID "'.$entry->id.'":';

            foreach ($entry->getAllErrors() as $attributeError)
            {
                $error .= "\n - {$attributeError}";
            }

            return $error;              
        }

        return true;
    }
    catch (\Exception $e)
    {
        return 'An exception was thrown while trying to save the entry with the ID “'.$this->_entryIds[$step].'”: '.$e->getMessage();
    }
}

This task step is based on one of the Craft default steps but the error gets output without the specific validation issues:

Encountered an error running task 1191 (Logic_UpdateEvents), step 1 of 1440: Encountered the following validation errors when trying to save entry with the ID "10295":

**Tags:** plugin-development, tasks, debugging

> **Comments:**
> **username_1**: What happens if you `Craft::log('error count = '.count($entry->getAllErrors()));`  
> **username_0**: `error count = 1`  
> **username_1**: Looks O.K. to me.  What if you do: `Craft::log('error = '.$entry->getAllErrors[0]);`?  
> **username_0**: `Encountered an error running task 1193 (Logic_UpdateEvents), step 1 of 1440: An exception was thrown while trying to save the entry with the ID “10295”: Property "Craft\EntryModel.getAllErrors" is not defined.`  
> **username_0**: Wait a second surely that needs to be `Craft::log('error = '.$entry->getAllErrors()[0])` ?  
> **username_0**: That returns the error correctly!  
> **username_0**: Any idea what caused the issue with the existing code?  
> **username_0**: I've tested a few variations but the line which is pumping out the errors `$error .= "\n - {$attributeError}";` is not happy with \n PHP_EOL, it would be great to know how to get line breaks output into the logs and awesome to get this fixed in the craft core versions.  
> **username_1**: Try using `PHP_EOL` instead of `\n`.  
> **username_0**: Already tried. No go. :(  
> **username_0**: @BradBell Ive discovered that this exact task works as expected when Dev Mode is off! not sure if that helps explain anything??  
> **username_1**: That's really weird!  

---

## 0 answers

