# When a job fails

Jobs fail: a partner's server is down, a password ran out, a disk is full, a file is not there. This page is about what a job does then, how you get told, and how to find the cause.

## What happens when a task fails

1. The error is noted. It is `{task_error}` from then on, and the task's name `{task_error_name}`.
2. If the server has a mail template named **JOB_FAILURE**, that mail is sent. See [Telling somebody](#telling-somebody).
3. The run goes on, in this order of preference:
   - along the failed task's **red line**, if it has one;
   - else to the task named **Default Failure**, if the job has one;
   - else **nowhere**: the path ends at the failed task.
4. When all paths have ended, the run is **Completed-Errors**.

So a job with no failure lines stops at its first error. Tasks behind the failed one do not run.

That is usually what you want: a Delete behind a Copy must not run when the Copy failed. It also means that a job whose last task is the Email "all done" sends nothing when something broke. Failure has to be drawn.

## Drawing what shall happen

| You want | Draw |
|---|---|
| a mail on any failure, anywhere in the job | one [Email](Task-Email.md) task named `Default Failure`, with no line into it. Every failed task without a red line leads there. |
| a mail when this one task fails | the red line of that task to an Email |
| to go on in spite of a failure | the red line to the same task as the green one |
| to try something else | the red line to the other way: a second server, another folder |
| to stop the whole job, other branches too | the red line to a [Kill](Task-Kill.md) |
| to try again later | the red line to a [Wait](Task-Wait.md) and from there back to the task. Count the tries with a variable, or use a [Loop](Task-Loop.md) with a limit, so that it ends. |

A mail about a failure usually wants: `{scheduleName}` the job, `{task_error_name}` the task, `{task_error}` the error, and `{full_log}` the log of the run so far.

Inside a [Loop](Task-Loop.md), a failed task without a red line ends the pass, and the loop decides whether to go on: **When a pass fails**.

## A failure is per task, not per file

A task that works through a hundred files and fails on the third has failed. What it hands on, and whether it went on to the other 97, depends on the task: see the task's page. A Copy stops at the file that failed; the files before it are copied.

For "copy what you can and tell me about the rest", put the Copy into a [Loop](Task-Loop.md) **For each item** with **When a pass fails: Go on with the next pass**.

Many tasks retry by themselves before they fail: a Copy has **Retries** and a wait between them. Raise those for a partner whose server is often busy.

## Telling somebody

| Way | Tells | Set up in |
|---|---|---|
| the mail template **JOB_FAILURE** | whoever is in the template, at every failed task of every job | the mail templates of the [Preferences](Prefs.md) |
| a task named **Default Failure** | whoever that job's task says | the job |
| the alert **Skipped scheduled job** | that a job did not start when it was due | [Alerts](Prefs-Alerts.md#jobs) |
| the alert **Job Engine Not Responding** | that nothing runs at all | [Alerts](Prefs-Alerts.md#jobs) |
| the Dashboard | "Jobs are failing", and which | [Overview](Jobs-Overview.md) |

A job that does not run is not a failed run, and no task of it can tell you. The two alerts are for that.

## Finding the cause

1. **Open the run** under [Active Jobs](Jobs-Running.md) with the status **With Error**. The canvas shows how far it came: the last task with counts under it.
2. **Read the log** of the run, from the end backwards to the first line of the failed task.
3. **Look at the items** of the task before: did it get what you thought?

What the usual errors mean:

| In the log | Usually |
|---|---|
| `java.io.FileNotFoundException … (No such file or directory)` | the folder to write to does not exist. A Copy does not make folders: put a [MakeDirectory](Task-MakeDirectory.md) before it. |
| `Permission denied`, `Access is denied` | the account the server runs as, or the user in the address, may not write there |
| `No task of the type "…"` | the job holds a task kind this server has no code for: [Custom](Task-Custom.md), or a kind from a newer version |
| `Connection refused`, `timed out`, `UnknownHostException` | the other server is down, a firewall is in the way, or the name is wrong |
| `Auth fail`, `Login failed`, `530` | the user name, password or key in the task is not accepted |
| "Found 0 … " and then nothing | no error at all: the Find matched nothing. Find has **Fail if no files are found**. |
| "v27 runs one line per dot: add a Branch task." | the job was drawn for CrushFTP 11: see [How a job flows](Jobs-Flow.md#jobs-from-crushftp-11) |
| "Conditionals only apply for Enterprise licenses." | the licence |
| nothing, and the run is not there | it never started: the schedule, the scheduler's switch, or an unsigned job. See [Schedules](Jobs-Schedules.md#when-nothing-runs) and [Approvals](Jobs-Approvals.md). |

An error is written to the log as the server got it, often as a Java error with the lines of the program behind it. The first line is the one that counts.

## Trying again

| To | Use |
|---|---|
| run it all again | **Re-Run** on the run |
| go on from the task that failed | **Retry from Failure**. The tasks before it are not repeated: files that were fetched are not fetched twice. |
| try the job step by step | [Breakpoints](Jobs-Breakpoints.md) |

## A run that hangs

A task that waits for a server that never answers can wait a long time. Give jobs a **Max runtime** in their [Setup](Jobs-Schedules.md#max-runtime), and tick **Single instance only**, so that a stuck run costs one run and they do not pile up. **Stop** on the run ends it; **Stop now** is offered when that does not work.

## Jobs that fail because the engine does

A run that ends because its [engine](Jobs-Engines.md) died or was restarted is resumed by itself when **Save state** is on and **If its engine is lost** says so. The Engines section lists such events under **What happened**. A job that brings its engine down more than once is moved to a runner of its own: see [How an engine stays healthy](Jobs-Engines-Health.md).
