# errors (/docs/go-sdk/errors)

{/* Code generated by gomarkdoc. DO NOT EDIT */}
# errors [#errors]

```go
import "github.com/daytona/clients/sdk-go/pkg/errors"
```

Package errors defines the typed error model used by the Daytona Go SDK.

Every error returned by the SDK is a \`\*DaytonaError\` carrying a human\-readable message, the HTTP \`StatusCode\` \(when applicable\), an optional machine\-readable \`Code\` / \`Source\` pair, and the response \`Headers\`. There are no per\-status struct types — a single concrete type keeps the surface small and unambiguous.

Branching is done with \`errors.Is\` against the package\-level sentinels:

```
if errors.Is(err, sdkerrors.ErrNotFound) {
    // any HTTP 404 from any source
}
if errors.Is(err, sdkerrors.ErrGitAuthFailed) {
    // precisely DAYTONA_DAEMON / GIT_AUTH_FAILED
}
if errors.Is(err, sdkerrors.ErrAuthentication) {
    // the same git-auth error ALSO matches the broader 401 sentinel,
    // mirroring the inheritance hierarchy of the other Daytona SDKs.
}
```

Reading metadata off an error is done with \`errors.As\`:

```
var de *sdkerrors.DaytonaError
if errors.As(err, &de) {
    log.Printf("status=%d code=%s source=%s", de.StatusCode, de.Code, de.Source)
}
```

When an SDK error was caused by an underlying Go error — most usefully a transport failure with no HTTP response \(connection reset, timeout, dropped stream\) — that error is kept in \`Err\` and exposed through \`Unwrap\`, so the standard matchers see through the \`\*DaytonaError\`. Whether such a failure is worth retrying is the caller's decision; retry only operations that are safe to repeat:

```
var netErr net.Error
if errors.Is(err, context.DeadlineExceeded) || (errors.As(err, &netErr) && netErr.Timeout()) {
    // transport timeout: retry if the operation is idempotent
}
```

## Index [#index]

- [Constants](<#constants>)
- [Variables](<#variables>)
- [func ConvertAPIError\(err error, httpResp \*http.Response\) error](<#ConvertAPIError>)
- [func ConvertToolboxError\(err error, httpResp \*http.Response\) error](<#ConvertToolboxError>)
- [type DaytonaAuthenticationError](<#DaytonaAuthenticationError>)
  - [func NewDaytonaAuthenticationError\(message string, headers http.Header\) \*DaytonaAuthenticationError](<#NewDaytonaAuthenticationError>)
  - [func \(e \*DaytonaAuthenticationError\) Unwrap\(\) error](<#DaytonaAuthenticationError.Unwrap>)
- [type DaytonaConflictError](<#DaytonaConflictError>)
  - [func NewDaytonaConflictError\(message string, headers http.Header\) \*DaytonaConflictError](<#NewDaytonaConflictError>)
  - [func \(e \*DaytonaConflictError\) Unwrap\(\) error](<#DaytonaConflictError.Unwrap>)
- [type DaytonaError](<#DaytonaError>)
  - [func NewDaytonaConnectionError\(message string\) \*DaytonaError](<#NewDaytonaConnectionError>)
  - [func NewDaytonaError\(message string, statusCode int, headers http.Header\) \*DaytonaError](<#NewDaytonaError>)
  - [func NewDaytonaErrorFromBody\(body \[\]byte, statusCode int, headers http.Header\) \*DaytonaError](<#NewDaytonaErrorFromBody>)
  - [func NewDaytonaTimeoutError\(message string\) \*DaytonaError](<#NewDaytonaTimeoutError>)
  - [func NewDaytonaValidationError\(message string, headers http.Header\) \*DaytonaError](<#NewDaytonaValidationError>)
  - [func NewQueueTimeoutError\(message string\) \*DaytonaError](<#NewQueueTimeoutError>)
  - [func NewSpotEvictedError\(message string\) \*DaytonaError](<#NewSpotEvictedError>)
  - [func WrapDaytonaError\(err error, message string, statusCode int, headers http.Header\) \*DaytonaError](<#WrapDaytonaError>)
  - [func \(e \*DaytonaError\) As\(target any\) bool](<#DaytonaError.As>)
  - [func \(e \*DaytonaError\) Error\(\) string](<#DaytonaError.Error>)
  - [func \(e \*DaytonaError\) Is\(target error\) bool](<#DaytonaError.Is>)
  - [func \(e \*DaytonaError\) Unwrap\(\) error](<#DaytonaError.Unwrap>)
- [type DaytonaForbiddenError](<#DaytonaForbiddenError>)
  - [func NewDaytonaForbiddenError\(message string, headers http.Header\) \*DaytonaForbiddenError](<#NewDaytonaForbiddenError>)
  - [func \(e \*DaytonaForbiddenError\) Unwrap\(\) error](<#DaytonaForbiddenError.Unwrap>)
- [type DaytonaNotFoundError](<#DaytonaNotFoundError>)
  - [func NewDaytonaNotFoundError\(message string, headers http.Header\) \*DaytonaNotFoundError](<#NewDaytonaNotFoundError>)
  - [func \(e \*DaytonaNotFoundError\) Unwrap\(\) error](<#DaytonaNotFoundError.Unwrap>)
- [type DaytonaRateLimitError](<#DaytonaRateLimitError>)
  - [func NewDaytonaRateLimitError\(message string, headers http.Header\) \*DaytonaRateLimitError](<#NewDaytonaRateLimitError>)
  - [func \(e \*DaytonaRateLimitError\) Unwrap\(\) error](<#DaytonaRateLimitError.Unwrap>)
- [type DaytonaServerError](<#DaytonaServerError>)
  - [func NewDaytonaServerError\(message string, statusCode int, headers http.Header\) \*DaytonaServerError](<#NewDaytonaServerError>)
  - [func \(e \*DaytonaServerError\) Unwrap\(\) error](<#DaytonaServerError.Unwrap>)
- [type DaytonaTimeoutError](<#DaytonaTimeoutError>)
  - [func \(e \*DaytonaTimeoutError\) Unwrap\(\) error](<#DaytonaTimeoutError.Unwrap>)
- [type DaytonaValidationError](<#DaytonaValidationError>)
  - [func \(e \*DaytonaValidationError\) Unwrap\(\) error](<#DaytonaValidationError.Unwrap>)


## Constants [#constants]

<a name="SourceAPI"></a>

```go
const (
    SourceAPI    = "DAYTONA_API"
    SourceDaemon = "DAYTONA_DAEMON"
    SourceProxy  = "DAYTONA_PROXY"
    // SourceSDK is stamped on errors synthesized by the SDK itself and never appears on the wire.
    SourceSDK = "DAYTONA_SDK"
)
```

## Variables [#variables]

<a name="ErrBadRequest"></a>

```go
var (
    // HTTP status-class sentinels. Names follow HTTP terminology.
    ErrBadRequest          = &DaytonaError{StatusCode: http.StatusBadRequest}
    ErrAuthentication      = &DaytonaError{StatusCode: http.StatusUnauthorized}
    ErrForbidden           = &DaytonaError{StatusCode: http.StatusForbidden}
    ErrNotFound            = &DaytonaError{StatusCode: http.StatusNotFound}
    ErrTimeout             = &DaytonaError{StatusCode: http.StatusRequestTimeout}
    ErrConflict            = &DaytonaError{StatusCode: http.StatusConflict}
    ErrGone                = &DaytonaError{StatusCode: http.StatusGone}
    ErrUnprocessableEntity = &DaytonaError{StatusCode: http.StatusUnprocessableEntity}
    ErrRateLimit           = &DaytonaError{StatusCode: http.StatusTooManyRequests}
    ErrInternalServer      = &DaytonaError{StatusCode: http.StatusInternalServerError}
    ErrBadGateway          = &DaytonaError{StatusCode: http.StatusBadGateway}
    ErrServiceUnavailable  = &DaytonaError{StatusCode: http.StatusServiceUnavailable}
    ErrGatewayTimeout      = &DaytonaError{StatusCode: http.StatusGatewayTimeout}

    // Deprecated: use ErrBadRequest. Kept so existing callers do not break.
    ErrValidation = ErrBadRequest
    // Deprecated: use ErrForbidden. Kept so existing callers do not break.
    ErrAuthorization = ErrForbidden

    // SDK-detected sandbox lifecycle.
    ErrQueueTimeout = &DaytonaError{StatusCode: http.StatusRequestTimeout, Source: SourceSDK, Code: "SANDBOX_QUEUE_TIMEOUT"}
    ErrSpotEvicted  = &DaytonaError{Source: SourceSDK, Code: "SANDBOX_SPOT_EVICTED"}

    // Daemon: git.
    ErrGitAuthFailed     = &DaytonaError{Source: SourceDaemon, Code: "GIT_AUTH_FAILED"}
    ErrGitRepoNotFound   = &DaytonaError{Source: SourceDaemon, Code: "GIT_REPO_NOT_FOUND"}
    ErrGitBranchNotFound = &DaytonaError{Source: SourceDaemon, Code: "GIT_BRANCH_NOT_FOUND"}
    ErrGitBranchExists   = &DaytonaError{Source: SourceDaemon, Code: "GIT_BRANCH_EXISTS"}
    ErrGitPushRejected   = &DaytonaError{Source: SourceDaemon, Code: "GIT_PUSH_REJECTED"}
    ErrGitDirtyWorktree  = &DaytonaError{Source: SourceDaemon, Code: "GIT_DIRTY_WORKTREE"}
    ErrGitMergeConflict  = &DaytonaError{Source: SourceDaemon, Code: "GIT_MERGE_CONFLICT"}
    // ErrGitTransportFailed matches network-level git failures: DNS, TLS,
    // connection, timeout.
    ErrGitTransportFailed = &DaytonaError{Source: SourceDaemon, Code: "GIT_TRANSPORT_FAILED"}
    // ErrGitRemoteRejected matches server-side rejections: pre-receive/update
    // hooks, branch protection, size/quota limits.
    ErrGitRemoteRejected = &DaytonaError{Source: SourceDaemon, Code: "GIT_REMOTE_REJECTED"}

    // Daemon: filesystem.
    ErrFileNotFound     = &DaytonaError{Source: SourceDaemon, Code: "FILE_NOT_FOUND"}
    ErrFileAccessDenied = &DaytonaError{Source: SourceDaemon, Code: "FILE_ACCESS_DENIED"}
    // ErrInvalidFilePath matches DAYTONA_DAEMON / INVALID_FILE_PATH (HTTP 400).
    ErrInvalidFilePath = &DaytonaError{Source: SourceDaemon, Code: "INVALID_FILE_PATH"}
    // ErrFileReadFailed matches DAYTONA_DAEMON / FILE_READ_FAILED (HTTP 500).
    ErrFileReadFailed = &DaytonaError{Source: SourceDaemon, Code: "FILE_READ_FAILED"}

    // Daemon: LSP.
    ErrLspServerNotInitialized = &DaytonaError{Source: SourceDaemon, Code: "LSP_SERVER_NOT_INITIALIZED"}

    // Daemon: process / session.
    ErrProcessExecutionTimeout = &DaytonaError{Source: SourceDaemon, Code: "PROCESS_EXECUTION_TIMEOUT"}
    ErrProcessNotFound         = &DaytonaError{Source: SourceDaemon, Code: "PROCESS_NOT_FOUND"}
    ErrSessionEnded            = &DaytonaError{Source: SourceDaemon, Code: "SESSION_ENDED"}
    ErrCommandAlreadyCompleted = &DaytonaError{Source: SourceDaemon, Code: "COMMAND_ALREADY_COMPLETED"}

    // Daemon: computer-use.
    ErrA11yUnavailable         = &DaytonaError{Source: SourceDaemon, Code: "A11Y_UNAVAILABLE"}
    ErrRecordingStillActive    = &DaytonaError{Source: SourceDaemon, Code: "RECORDING_STILL_ACTIVE"}
    ErrRecordingFfmpegNotFound = &DaytonaError{Source: SourceDaemon, Code: "RECORDING_FFMPEG_NOT_FOUND"}
)
```

<a name="ConvertAPIError"></a>
## func ConvertAPIError [#func-convertapierror]

```go
func ConvertAPIError(err error, httpResp *http.Response) error
```

ConvertAPIError converts an error returned by the generated api\-client\-go \(and an optional \`\*http.Response\`\) into a \`\*DaytonaError\`.

<a name="ConvertToolboxError"></a>
## func ConvertToolboxError [#func-converttoolboxerror]

```go
func ConvertToolboxError(err error, httpResp *http.Response) error
```

ConvertToolboxError converts an error returned by the generated toolbox\-api\-client\-go into a \`\*DaytonaError\`.

<a name="DaytonaAuthenticationError"></a>
## type DaytonaAuthenticationError [#type-daytonaauthenticationerror]

Deprecated: match with \`errors.Is\(err, ErrAuthentication\)\` instead.

```go
type DaytonaAuthenticationError struct{ *DaytonaError }
```

<a name="NewDaytonaAuthenticationError"></a>
### func NewDaytonaAuthenticationError [#func-newdaytonaauthenticationerror]

```go
func NewDaytonaAuthenticationError(message string, headers http.Header) *DaytonaAuthenticationError
```

Deprecated: use NewDaytonaError\(message, http.StatusUnauthorized, headers\).

<a name="DaytonaAuthenticationError.Unwrap"></a>
### func \(\*DaytonaAuthenticationError\) Unwrap [#func-daytonaauthenticationerror-unwrap]

```go
func (e *DaytonaAuthenticationError) Unwrap() error
```



<a name="DaytonaConflictError"></a>
## type DaytonaConflictError [#type-daytonaconflicterror]

Deprecated: match with \`errors.Is\(err, ErrConflict\)\` instead.

```go
type DaytonaConflictError struct{ *DaytonaError }
```

<a name="NewDaytonaConflictError"></a>
### func NewDaytonaConflictError [#func-newdaytonaconflicterror]

```go
func NewDaytonaConflictError(message string, headers http.Header) *DaytonaConflictError
```

Deprecated: use NewDaytonaError\(message, http.StatusConflict, headers\).

<a name="DaytonaConflictError.Unwrap"></a>
### func \(\*DaytonaConflictError\) Unwrap [#func-daytonaconflicterror-unwrap]

```go
func (e *DaytonaConflictError) Unwrap() error
```



<a name="DaytonaError"></a>
## type DaytonaError [#type-daytonaerror]

DaytonaError is the single error type returned by the SDK. Use \`errors.As\(err, &target \*DaytonaError\)\` to read its fields and \`errors.Is\(err, sentinel\)\` to branch on the kind.

```go
type DaytonaError struct {
    Message    string
    StatusCode int
    Code       string
    Source     string
    Headers    http.Header
    // Err is the underlying error, if any (for example the *url.Error of a
    // request that never got a response). It is returned by Unwrap and is
    // not part of Error() and is not serialized to JSON.
    Err error `json:"-"`
}
```

<a name="NewDaytonaConnectionError"></a>
### func NewDaytonaConnectionError [#func-newdaytonaconnectionerror]

```go
func NewDaytonaConnectionError(message string) *DaytonaError
```

NewDaytonaConnectionError is a convenience constructor for transport\-level failures with no HTTP response \(DNS, dial, TLS, mid\-request drop\).

<a name="NewDaytonaError"></a>
### func NewDaytonaError [#func-newdaytonaerror]

```go
func NewDaytonaError(message string, statusCode int, headers http.Header) *DaytonaError
```

NewDaytonaError builds a DaytonaError with the given message, status code and headers. \`Source\` is left empty for SDK\-internal errors unless the translation layer populates it from a server\-side envelope. Most callers should use this directly; the sentinels below are for branching with \`errors.Is\`, not for constructing errors.

<a name="NewDaytonaErrorFromBody"></a>
### func NewDaytonaErrorFromBody [#func-newdaytonaerrorfrombody]

```go
func NewDaytonaErrorFromBody(body []byte, statusCode int, headers http.Header) *DaytonaError
```

NewDaytonaErrorFromBody parses a JSON response body and builds a DaytonaError. When the body carries its own \`statusCode\` field that overrides the caller\-supplied one \(server\-side envelopes are authoritative\).

<a name="NewDaytonaTimeoutError"></a>
### func NewDaytonaTimeoutError [#func-newdaytonatimeouterror]

```go
func NewDaytonaTimeoutError(message string) *DaytonaError
```

NewDaytonaTimeoutError is a convenience constructor for client\-side timeouts. Equivalent to \`NewDaytonaError\(message, http.StatusRequestTimeout, nil\)\`.

<a name="NewDaytonaValidationError"></a>
### func NewDaytonaValidationError [#func-newdaytonavalidationerror]

```go
func NewDaytonaValidationError(message string, headers http.Header) *DaytonaError
```

Deprecated: use NewDaytonaError\(message, http.StatusBadRequest, headers\).

<a name="NewQueueTimeoutError"></a>
### func NewQueueTimeoutError [#func-newqueuetimeouterror]

```go
func NewQueueTimeoutError(message string) *DaytonaError
```

NewQueueTimeoutError is a convenience constructor for SDK\-detected sandbox queue timeout destruction. It matches both [ErrQueueTimeout](<#ErrBadRequest>) and [ErrTimeout](<#ErrBadRequest>).

<a name="NewSpotEvictedError"></a>
### func NewSpotEvictedError [#func-newspotevictederror]

```go
func NewSpotEvictedError(message string) *DaytonaError
```

NewSpotEvictedError is a convenience constructor for SDK\-detected spot preemption destruction.

<a name="WrapDaytonaError"></a>
### func WrapDaytonaError [#func-wrapdaytonaerror]

```go
func WrapDaytonaError(err error, message string, statusCode int, headers http.Header) *DaytonaError
```

WrapDaytonaError builds a DaytonaError like NewDaytonaError and keeps err as its cause, reachable through Unwrap. The message is used verbatim; err is not appended to it.

<a name="DaytonaError.As"></a>
### func \(\*DaytonaError\) As [#func-daytonaerror-as]

```go
func (e *DaytonaError) As(target any) bool
```

As lets \`errors.As\` populate the deprecated typed errors with their original status\-code semantics, even though the SDK only produces \*DaytonaError. Runs only after the stdlib's direct assignability check, so \`errors.As\(err, &de\)\` with a \*DaytonaError target is unaffected.

<a name="DaytonaError.Error"></a>
### func \(\*DaytonaError\) Error [#func-daytonaerror-error]

```go
func (e *DaytonaError) Error() string
```



<a name="DaytonaError.Is"></a>
### func \(\*DaytonaError\) Is [#func-daytonaerror-is]

```go
func (e *DaytonaError) Is(target error) bool
```

Is implements the \`errors.Is\` contract. A target matches when it is one of the package\-level sentinels and either:

- the target carries a non\-empty \`Code\`, in which case BOTH \`Source\` and \`Code\` must match exactly \(domain\-code sentinel\), or
- the target carries a non\-zero \`StatusCode\`, in which case the receiver's \`StatusCode\` must match \(status\-class sentinel\).

Because the SDK always stamps the HTTP status alongside the domain code, \`errors.Is\(err, ErrGitAuthFailed\)\` and \`errors.Is\(err, ErrAuthentication\)\` both match the same underlying error — mirroring the inheritance hierarchy used by the Python/TypeScript/Java SDKs.

<a name="DaytonaError.Unwrap"></a>
### func \(\*DaytonaError\) Unwrap [#func-daytonaerror-unwrap]

```go
func (e *DaytonaError) Unwrap() error
```

Unwrap returns the underlying error, so \`errors.Is\` / \`errors.As\` can match the cause \(for example \`context.DeadlineExceeded\`, \`io.ErrUnexpectedEOF\`, \`syscall.ECONNRESET\`, or a \`net.Error\`\). It returns nil when the error has no cause.

<a name="DaytonaForbiddenError"></a>
## type DaytonaForbiddenError [#type-daytonaforbiddenerror]

Deprecated: match with \`errors.Is\(err, ErrForbidden\)\` instead.

```go
type DaytonaForbiddenError struct{ *DaytonaError }
```

<a name="NewDaytonaForbiddenError"></a>
### func NewDaytonaForbiddenError [#func-newdaytonaforbiddenerror]

```go
func NewDaytonaForbiddenError(message string, headers http.Header) *DaytonaForbiddenError
```

Deprecated: use NewDaytonaError\(message, http.StatusForbidden, headers\).

<a name="DaytonaForbiddenError.Unwrap"></a>
### func \(\*DaytonaForbiddenError\) Unwrap [#func-daytonaforbiddenerror-unwrap]

```go
func (e *DaytonaForbiddenError) Unwrap() error
```



<a name="DaytonaNotFoundError"></a>
## type DaytonaNotFoundError [#type-daytonanotfounderror]

Deprecated: match with \`errors.Is\(err, ErrNotFound\)\` instead.

```go
type DaytonaNotFoundError struct{ *DaytonaError }
```

<a name="NewDaytonaNotFoundError"></a>
### func NewDaytonaNotFoundError [#func-newdaytonanotfounderror]

```go
func NewDaytonaNotFoundError(message string, headers http.Header) *DaytonaNotFoundError
```

Deprecated: use NewDaytonaError\(message, http.StatusNotFound, headers\).

<a name="DaytonaNotFoundError.Unwrap"></a>
### func \(\*DaytonaNotFoundError\) Unwrap [#func-daytonanotfounderror-unwrap]

```go
func (e *DaytonaNotFoundError) Unwrap() error
```



<a name="DaytonaRateLimitError"></a>
## type DaytonaRateLimitError [#type-daytonaratelimiterror]

Deprecated: match with \`errors.Is\(err, ErrRateLimit\)\` instead.

```go
type DaytonaRateLimitError struct{ *DaytonaError }
```

<a name="NewDaytonaRateLimitError"></a>
### func NewDaytonaRateLimitError [#func-newdaytonaratelimiterror]

```go
func NewDaytonaRateLimitError(message string, headers http.Header) *DaytonaRateLimitError
```

Deprecated: use NewDaytonaError\(message, http.StatusTooManyRequests, headers\).

<a name="DaytonaRateLimitError.Unwrap"></a>
### func \(\*DaytonaRateLimitError\) Unwrap [#func-daytonaratelimiterror-unwrap]

```go
func (e *DaytonaRateLimitError) Unwrap() error
```



<a name="DaytonaServerError"></a>
## type DaytonaServerError [#type-daytonaservererror]

Deprecated: match with \`errors.Is\(err, ErrInternalServer\)\` or compare StatusCode \>= 500 on \*DaytonaError instead.

```go
type DaytonaServerError struct{ *DaytonaError }
```

<a name="NewDaytonaServerError"></a>
### func NewDaytonaServerError [#func-newdaytonaservererror]

```go
func NewDaytonaServerError(message string, statusCode int, headers http.Header) *DaytonaServerError
```

Deprecated: use NewDaytonaError\(message, statusCode, headers\).

<a name="DaytonaServerError.Unwrap"></a>
### func \(\*DaytonaServerError\) Unwrap [#func-daytonaservererror-unwrap]

```go
func (e *DaytonaServerError) Unwrap() error
```



<a name="DaytonaTimeoutError"></a>
## type DaytonaTimeoutError [#type-daytonatimeouterror]

Deprecated: match with \`errors.Is\(err, ErrTimeout\)\` or \`errors.Is\(err, ErrGatewayTimeout\)\` instead.

```go
type DaytonaTimeoutError struct{ *DaytonaError }
```

<a name="DaytonaTimeoutError.Unwrap"></a>
### func \(\*DaytonaTimeoutError\) Unwrap [#func-daytonatimeouterror-unwrap]

```go
func (e *DaytonaTimeoutError) Unwrap() error
```



<a name="DaytonaValidationError"></a>
## type DaytonaValidationError [#type-daytonavalidationerror]

Deprecated: match with \`errors.Is\(err, ErrBadRequest\)\` instead.

```go
type DaytonaValidationError struct{ *DaytonaError }
```

<a name="DaytonaValidationError.Unwrap"></a>
### func \(\*DaytonaValidationError\) Unwrap [#func-daytonavalidationerror-unwrap]

```go
func (e *DaytonaValidationError) Unwrap() error
```
