Read method. Read is a synchronous operation that retrieves the current state of a resource.
What Read does
The agent callsRead to get the current state of a resource from the infrastructure. This happens:
- When a user runs
formae statusorformae inventory - During synchronization (the agent periodically reads all managed resources)
- Before an update (to detect out-of-band changes)
ReadRequest
The agent sends aReadRequest to retrieve the current state of a resource:
ReadResult
Unlike mutating operations that returnProgressResult, Read returns a simpler ReadResult directly:
ErrorCode to NotFound (don’t return a Go error). See 10 - Error handling for more on error codes.
Test
Add a test tosftp_test.go:
Test pattern
Implementation
Verify
Run the test to confirm Read retrieves file properties correctly:Handling NotFound
Now we need to handle a critical edge case: what happens when the resource doesn’t exist?Why NotFound matters
The agent periodically calls Read on all managed resources to synchronize formae’s state with the actual infrastructure. This is how formae detects out-of-band changes, modifications made outside of formae (e.g., someone manually deleted a file via SSH). When a resource no longer exists:- The plugin must return a result with
ErrorCode = NotFound - The plugin must not return an error
- The agent then marks the resource as deleted in its inventory
NotFound test
NotFound implementation
Update the error handling in Read:Verify
Summary
The NotFound handling is critical: the agent relies on it to detect out-of-band deletions and keep its inventory in sync with reality.
Next: 07 - Update

