|
2 | 2 |
|
3 | 3 | This guide shows the intended protobuf shape for typed error payload messages that use `trogon.error.v1alpha1`. |
4 | 4 |
|
| 5 | +Trogon error annotations are descriptor-time templates for the Google RPC rich error model. They describe the `google.rpc.Status` and `google.rpc.ErrorInfo` details a runtime should emit when the typed error occurs. |
| 6 | + |
5 | 7 | ## Example |
6 | 8 |
|
7 | 9 | ```proto |
@@ -38,18 +40,68 @@ message ResourceAvailabilityError { |
38 | 40 | } |
39 | 41 | ``` |
40 | 42 |
|
| 43 | +## Runtime Mapping |
| 44 | + |
| 45 | +When a runtime emits this error, it should build the protocol-native error envelope from the template: |
| 46 | + |
| 47 | +| Trogon option | Google RPC field | |
| 48 | +|---------------|------------------| |
| 49 | +| `code` | `google.rpc.Status.code` | |
| 50 | +| `message` | `google.rpc.Status.message` | |
| 51 | +| `domain` | `google.rpc.ErrorInfo.domain` | |
| 52 | +| `reason` | `google.rpc.ErrorInfo.reason` | |
| 53 | +| `metadata` | `google.rpc.ErrorInfo.metadata` | |
| 54 | +| Payload fields | `google.rpc.ErrorInfo.metadata` | |
| 55 | +| `help_links` | `google.rpc.Help.links` | |
| 56 | + |
| 57 | +For the example above, a runtime could emit this JSON representation of a `google.rpc.Status`: |
| 58 | + |
| 59 | +```json |
| 60 | +{ |
| 61 | + "code": 8, |
| 62 | + "message": "Requested resources are unavailable.", |
| 63 | + "details": [ |
| 64 | + { |
| 65 | + "@type": "type.googleapis.com/google.rpc.ErrorInfo", |
| 66 | + "reason": "RESOURCE_AVAILABILITY", |
| 67 | + "domain": "compute.googleapis.com", |
| 68 | + "metadata": { |
| 69 | + "component": "compute", |
| 70 | + "region": "us-east-1", |
| 71 | + "service": "compute-api", |
| 72 | + "vm_type": "n2-standard-16", |
| 73 | + "zone": "us-east1-b" |
| 74 | + } |
| 75 | + }, |
| 76 | + { |
| 77 | + "@type": "type.googleapis.com/google.rpc.Help", |
| 78 | + "links": [ |
| 79 | + { |
| 80 | + "description": "Compute Docs", |
| 81 | + "url": "https://docs.acme.com/compute" |
| 82 | + } |
| 83 | + ] |
| 84 | + } |
| 85 | + ] |
| 86 | +} |
| 87 | +``` |
| 88 | + |
41 | 89 | ## Notes |
42 | 90 |
|
43 | 91 | - `template` is a message field, so it carries proto3 presence by default. |
44 | | -- The template captures the parts of the error contract that never vary at runtime: `domain`, `reason`, `code`, default `message`, error-level `visibility`, `help_links`, and fixed `metadata` entries. |
| 92 | +- The template captures the parts of the Google RPC error contract that never vary at runtime: `domain`, `reason`, `code`, default `message`, error-level `visibility`, `help_links`, and fixed `metadata` entries. |
| 93 | +- `domain` and `reason` describe the `google.rpc.ErrorInfo` identity for this error. `reason` must be stable within the `domain`. |
45 | 94 | - `metadata` declares contract-level constants (component, team, subsystem) that attach to every emission without occupying a wire field. Keys must be unique within the template and must not collide with field names on the payload message. |
46 | 95 | - Payload fields hold the dynamic context for a single emission. Each field can carry `FieldOptions`: |
47 | 96 | - `visibility` controls who sees the field at runtime (defaults to `INTERNAL`). |
48 | 97 | - `value_policy.default_value` substitutes a value when the runtime field is empty. |
49 | 98 | - `value_policy.value` pins the field to a contract-fixed value; the runtime payload is ignored on emit. |
| 99 | +- `visibility` is a Trogon filtering policy. It is not part of `google.rpc.ErrorInfo`. |
50 | 100 |
|
51 | 101 | ## References |
52 | 102 |
|
53 | 103 | - [../../proto/trogon/error/v1alpha1/code.proto](../../proto/trogon/error/v1alpha1/code.proto) |
54 | 104 | - [../../proto/trogon/error/v1alpha1/options.proto](../../proto/trogon/error/v1alpha1/options.proto) |
55 | 105 | - [../../proto/trogon/error/v1alpha1/visibility.proto](../../proto/trogon/error/v1alpha1/visibility.proto) |
| 106 | +- [Google RPC Status](https://cloud.google.com/tasks/docs/reference/rpc/google.rpc#status) |
| 107 | +- [Google RPC ErrorInfo](https://cloud.google.com/spanner/docs/reference/rpc/google.rpc#errorinfo) |
0 commit comments