# JobErrorCodes

> Tracon documentation. Tracon is a .NET package family that adds a control
> plane on Microsoft Agent Framework, published as NuGet packages that run
> inside your own ASP.NET Core application.
>
> Page: https://tracon.dev/api/tracon.joberrorcodes/
> Summary: JobErrorCodes: The stable codes a job's JobRecord.ErrorMessage carries when the failure comes from the queue itself rather than from a handler.

<div class="api-provenance">Namespace Tracon · Assembly <code>Tracon.Abstractions.dll</code></div>

The stable codes a job's [JobRecord.ErrorMessage](/api/tracon.jobrecord/#Tracon_JobRecord_ErrorMessage) carries when
the failure comes from the queue itself rather than from a handler.

```csharp
public static class JobErrorCodes
```

<dl class="api-relations"><dt>Inheritance</dt><dd><a href="https://learn.microsoft.com/dotnet/api/system.object">object</a> ← <a href="/api/tracon.joberrorcodes/">JobErrorCodes</a></dd><dt>Inherited Members</dt><dd><a href="https://learn.microsoft.com/dotnet/api/system.object.gettype">object.GetType()</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone">object.MemberwiseClone()</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.tostring">object.ToString()</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)">object.Equals(object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)">object.Equals(object?, object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.referenceequals">object.ReferenceEquals(object?, object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.gethashcode">object.GetHashCode()</a></dd></dl>

## Remarks

A code is machine readable and never changes; the prose around it may. A
consumer that has to tell "nobody handles this key" apart from "the
handler threw" matches on the code, not on the sentence.

## Fields

### <a id="Tracon_JobErrorCodes_AttemptsExhausted"></a> AttemptsExhausted

The job was leased again after its lease ran out — the worker running
it stopped renewing, most often because its process died — and the new
attempt is past the job's attempt limit, so the job failed without
running again.

```csharp
public const string AttemptsExhausted = "tracon.job.attempts-exhausted"
```

#### Field Value

 [string](https://learn.microsoft.com/dotnet/api/system.string)

#### Remarks

The limit is [JobRecord.MaxAttempts](/api/tracon.jobrecord/#Tracon_JobRecord_MaxAttempts), or the scheduling
`MaxAttempts` setting when the job carries none. A lease that runs
out counts as an attempt, because the work it covered may have had side
effects; a job limited to one attempt is never run twice.

The handler never ran, so a record the handler would have closed — a
queued agent run, say — keeps the status it had when the earlier attempt
stopped. Run reconciliation closes such a run.

The earlier worker is usually dead, but it may only have lost its lease
(its renewals kept failing). If it then finishes, its result does not
change the job: a job that reached a final status keeps it.

### <a id="Tracon_JobErrorCodes_HandlerActivationFailed"></a> HandlerActivationFailed

The handler registered for the job's
[JobRecord.HandlerKey](/api/tracon.jobrecord/#Tracon_JobRecord_HandlerKey) could not be constructed — one of
its dependencies is missing from the container — so the job failed
without ever being executed.

```csharp
public const string HandlerActivationFailed = "tracon.job.handler-activation-failed"
```

#### Field Value

 [string](https://learn.microsoft.com/dotnet/api/system.string)

#### Remarks

A configuration mistake, not a transient one: retrying cannot fix a
dependency that is not registered. The job is therefore failed rather
than released, so it does not re-lease forever. The exception's own
detail goes to the log, under the correlation id the message carries.

### <a id="Tracon_JobErrorCodes_MaxDurationExceeded"></a> MaxDurationExceeded

The attempt ran longer than the job's time limit
([JobRecord.MaxDuration](/api/tracon.jobrecord/#Tracon_JobRecord_MaxDuration), or
`TraconSchedulingOptions.MaxDurationByHandlerKey` for its key), the worker
cancelled the handler's token, and the handler stopped with an error.

```csharp
public const string MaxDurationExceeded = "tracon.job.max-duration-exceeded"
```

#### Field Value

 [string](https://learn.microsoft.com/dotnet/api/system.string)

#### Remarks

The attempt counts like any failed one: the job is leased again while attempts
are left, and fails with this code on its last. The limit is per attempt, so
the next attempt gets the full time again.

A run the handler had started is cancelled with the token, so it ends
`Canceled`. The built-in workflow handlers treat the limit as the end of
the work, not as an interruption: a queued workflow run's job fails at once with
this code, a workflow batch fails the item whose run was stopped (and the job, with
this code, when no item is left for another attempt), and recovery
(`Tracon:Workflows:ResumeInterruptedRuns`) never continues a run the limit
stopped. Its row carries the error type `job_max_duration_exceeded`.

### <a id="Tracon_JobErrorCodes_UnknownHandlerKey"></a> UnknownHandlerKey

No [IJobHandler](/api/tracon.ijobhandler/) is registered for the job's
[JobRecord.HandlerKey](/api/tracon.jobrecord/#Tracon_JobRecord_HandlerKey), so the job failed without ever
being executed.

```csharp
public const string UnknownHandlerKey = "tracon.job.unknown-handler-key"
```

#### Field Value

 [string](https://learn.microsoft.com/dotnet/api/system.string)

#### Remarks

The persisted message deliberately does not repeat the key: an
unregistered key may have come from an untrusted source, and
[JobRecord.ErrorMessage](/api/tracon.jobrecord/#Tracon_JobRecord_ErrorMessage) is read back over HTTP and shown
in the UI. The raw key goes to the log only, tagged with the same
correlation id the message carries.

## Methods

### <a id="Tracon_JobErrorCodes_Format_System_String_System_String_"></a> Format\(string, string\)

Formats the persisted message for `code`.

```csharp
public static string Format(string code, string correlationId)
```

#### Parameters

`code` [string](https://learn.microsoft.com/dotnet/api/system.string)

One of this class's constants.

`correlationId` [string](https://learn.microsoft.com/dotnet/api/system.string)

The id also written to the log entry carrying the untruncated detail
(Tracon uses a short random hexadecimal id).

#### Returns

 [string](https://learn.microsoft.com/dotnet/api/system.string)

The message to persist.

#### Exceptions

 [ArgumentException](https://learn.microsoft.com/dotnet/api/system.argumentexception)

`code` is empty.

 [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception)

`correlationId` is [null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null).
