Skip to content

Commit

Permalink
Document links and improve failure documentation (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
bergundy authored Feb 5, 2025
1 parent 37755b4 commit f25ab64
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,37 @@ operation failures and framework level HTTP request errors.

The `Details` field is encoded and it is up to the library user to encode to and decode from it.

A failure can be either directly attached to `HandlerError` and `OperationError` instances by providing `FailureError`
as the `Cause`, or indirectly by implementing the `FailureConverter` interface, which can translate arbitrary user
defined errors to `Failure` instances and back.

### Links

Nexus operations can bi-directionally link the caller and handler for tracing the execution path. A caller may provide
a set of `Link` objects via `StartOperationOptions` that the handler may log or attach to any underlying resources
backing the operation. A handler may attach backlinks when responding to a `StartOperation` request via the a
`AddHandlerLinks` method.

#### Handler

```go
func (h *myArbitraryLengthOperation) Start(ctx context.Context, input MyInput, options nexus.StartOperationOptions) (nexus.HandlerStartOperationResult[MyOutput], error) {
output, backlinks, _ := createMyBackingResourceAndAttachCallerLinks(ctx, input, options.Links)
nexus.AddHandlerLinks(ctx, backlinks)
return output, nil
}

result, _ := nexus.StartOperation(ctx, client, operation, MyInput{Field: "value"}, nexus.StartOperationOptions{
Links: []nexus.Link{
{
Type: "org.my.MyResource",
URL: &url.URL{/* ... */},
},
},
})
fmt.Println("got result with backlinks", result.Links)
```

## Contributing

### Prerequisites
Expand Down

0 comments on commit f25ab64

Please sign in to comment.