Skip to main content
This section covers error handling patterns and the OperationErrorCode type in depth.

NotFound revisited

We’ve already seen NotFound in action during 06 - Read and 08 - Delete. This error code deserves special attention because its meaning changes depending on the operation: The agent handles NotFound intelligently based on context, so your plugin should return it whenever the resource doesn’t exist rather than trying to handle the semantics yourself.

OperationErrorCode

When an operation fails, set the ErrorCode field to tell the agent what went wrong:

Recoverable vs non-recoverable errors

The agent classifies errors into two categories:
  • Recoverable errors: transient failures that might succeed on retry. The agent will retry up to a configurable number of attempts (default: 3 retries, so 4 total attempts).
  • Non-recoverable errors: permanent failures that won’t be resolved by retrying. The agent fails the operation immediately.

Recoverable errors

Use these when the failure might be temporary:

Non-recoverable errors

Use these when retrying won’t help:

StatusMessage

The StatusMessage field provides human-readable context about the error. Always set it when returning a failure:
The agent displays StatusMessage in CLI output and logs, so make it descriptive enough that operators can diagnose the issue.

Mapping infrastructure errors

When your plugin calls an external API, map the response to the appropriate error code. Here’s a pattern from the OVH plugin:
For our SFTP plugin, we only need to handle a few cases:

Never return Go errors for expected conditions

Plugin methods return (Result, error). Reserve the error return for truly exceptional conditions like panics or bugs. Expected conditions should be communicated through the result:

Complete error handling example

Here’s how a well-structured Create implementation handles errors:

Summary

With proper error handling, your plugin integrates smoothly with the agent’s retry logic and provides clear feedback to users when things go wrong.
Next: 11 - Conformance tests - Set up conformance tests and continuous integration