Skip to content

Commit 7da247d

Browse files
committed
AIP-193: First part of restructuring the description of Status fields
(This doesn't include anything about the details "payloads" yet.)
1 parent a1d988c commit 7da247d

1 file changed

Lines changed: 52 additions & 83 deletions

File tree

aip/general/0193.md

Lines changed: 52 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -34,98 +34,67 @@ is necessary, you **should** provide a link where a reader can get more
3434
information or ask questions to help resolve the issue. It is also
3535
important to [set the right tone][writing-tone] when writing messages.
3636

37-
### Error Response
38-
39-
#### google.rpc.Status
40-
41-
Services must return a [`google.rpc.Status`][Status] message when an API
42-
error occurs. For each error the service **must** populate the `message`
43-
string in [`google.rpc.Status`][Status] as follows:
44-
45-
- Present a developer-facing, human-readable "debug message"
46-
- Present the message in the service's native language to explain both
47-
the error and offer an actionable resolution to it ([citation][Error
48-
model])
49-
50-
**Note:** Sometimes a service will elect to always present
51-
`Status.message` in English rather than the application's native
52-
language so that messages are easily searchable in common knowledge
53-
bases, such as StackOverflow™.
54-
55-
Important points:
56-
57-
- This `message` string is considered a problem description. It is
58-
intended for developers to understand the problem and is more
59-
detailed than [`ErrorInfo.reason`][ErrorInfo-reason], discussed in the
60-
next section.
61-
- Use simple descriptive language that is easy to understand (without
62-
technical jargon) to clearly state the problem that results in an
63-
error.
64-
- For pre-existing (brownfield) APIs, the information in
65-
`google.rpc.Status` already exists and can’t be changed. In this
66-
case, do not edit anything in this `google.rpc.Status`, because some
67-
users might have automation running against the pre-existing content.
68-
For example, any changes in text for the `message` string could cause
69-
breakages. For more information, see [Changing Error
70-
Messages](#changing-error-messages).
71-
72-
##### [google.rpc.Status payload][Status]
37+
The following sections describe the fields of `google.rpc.Status`.
7338

74-
Details of this object are summarized in the following fields, field
75-
descriptions, and examples:
39+
### Status.message
7640

77-
- `code int32`
78-
- The status code, which **must** be an enum value of
79-
[`google.rpc.Code`][Code].
80-
- *Example*: 8
81-
- `message string`
82-
- A developer-facing error message, which **should** be in English.
83-
Any user-facing error message **should** be located in the
84-
LocalizedMessage payload.
85-
- *Example message*: \"The zone \'us-east1-a\' does not have enough
86-
resources available to fulfill the request. Try a different zone, or
87-
try again later.\"
88-
- `details Object (repeated)`
89-
- Additional text details about the error, which includes
90-
`ErrorInfo`,`LocalizedMessage`, and so on.
91-
- *Example*: Described in the [ErrorDetails](#error-details) section.
92-
93-
94-
**Important:** In the context of the `google.rpc.Status` protobuf
95-
message, the value of the field `code` is the numeric equivalent to the
96-
enum value chosen from [`google.rpc.Code`][Code]. For example, if
97-
[`INVALID_ARGUMENT`][InvalidArgument] is chosen, the value of `code`
98-
will be `3` (in the context of the Protobuf message,
99-
`google.rpc.Status`). However, when the error is expressed as JSON, as
100-
in the [sample above](#json-representation), the value of the field by
101-
the same name, `"code"`, is the HTTP status code equivalent of the
102-
selected `google.rpc.Code`. For example, the value of the field `"code"`
103-
in the JSON reply would be `400`.
104-
105-
#### [ErrorDetails][details]
41+
The `message` field is a developer-facing, human-readable "debug message"
42+
which **should** be in English. (Localized messages are expressed using
43+
a `LocalizedMessage` within the `details` field. See
44+
[`LocalizedMessage`](#localizedmessage) for more details.) Any dynamic aspects of
45+
the message **must** be included as metadata within the `ErrorInfo` that appears
46+
in [`details`](#status-details).
10647

107-
Google defines a set of [standard detail payloads][details] for error
108-
details, which cover most common needs for API errors. Services
109-
**should** use these standard detail payloads when feasible.
48+
The message is considered a problem description. It is intended for
49+
developers to understand the problem and is more detailed than
50+
[`ErrorInfo.reason`][ErrorInfo-reason], discussed [later](#errorinfo).
11051

111-
Structured details with machine-readable identifiers **must** be used so
112-
that users can write code against specific aspects of the error. Error
113-
message strings **may** change over time; however, if an error message
114-
does not have a machine-readable identifier *in addition to* the `code`
115-
string, changing the error message **must** be considered a
116-
backwards-incompatible change.
52+
Messages **should** use simple descriptive language that is easy to understand
53+
(without technical jargon) to clearly state the problem that results in an
54+
error.
55+
56+
For pre-existing (brownfield) APIs which have returned errors without
57+
additional details in the past, the value of `message` must remain the same
58+
for any given error, as developers have previously had no option but to use
59+
this for error handling. For more information, see
60+
[Changing Error Messages](#changing-error-messages).
61+
62+
### Status.code
63+
64+
The `code` field is the status code, which **must** be the numeric value of
65+
one of the elements of the [`google.rpc.Code`][Code] enum.
11766

118-
The following section describes `ErrorInfo`, `LocalizedMessage`, and
119-
`Help` in more detail.
67+
For example, the value `5` is the numeric value of the `NOT_FOUND`
68+
enum element.
12069

121-
##### Uniqueness
70+
### Status.details
71+
72+
The `details` field allows messages with additional error information to
73+
be included in the error response, each packed in a `google.protobuf.Any`
74+
message.
75+
76+
Google defines a set of [standard detail payloads][details] for error
77+
details, which cover most common needs for API errors.
78+
Services **should** use these standard detail payloads when feasible.
12279

12380
Each type of detail payload **must** be included at most once. For
12481
example, there **must not** be more than one [`BadRequest`][BadRequest]
12582
message in the `details`, but there **may** be a `BadRequest` and a
12683
[`PreconditionFailure`][PreconditionFailure].
12784

128-
##### ErrorInfo payload
85+
Structured details with machine-readable identifiers **must** be used so
86+
that users can write code against specific aspects of the error. Error
87+
message strings **may** change over time; however, if an error message
88+
does not have a machine-readable identifier *in addition to* the message,
89+
changing the error message **must** be considered a backwards-incompatible
90+
change. For more information, see
91+
[Changing Error Messages](#changing-error-messages).
92+
93+
All error responses **must** include an `ErrorInfo` message within `details`.
94+
95+
The following sections describe the most common standard detail payloads.
96+
97+
#### ErrorInfo
12998

13099
The [`ErrorInfo`][ErrorInfo] message is the required way to send a
131100
machine-readable identifier. All error responses **must** include an
@@ -243,15 +212,15 @@ map for the error payload to be backwards compatible, even if the value
243212
for a particular key is empty. Keys **must** be expressed as lower
244213
camel-case.
245214
246-
##### Localization
215+
#### Localization
247216
248217
If a localized error message is required, the service **must** include
249218
[`google.rpc.LocalizedMessage`][LocalizedMessage] in `Status.details`.
250219
The value of the `Status.message` string **should** be presented in the
251220
service's native language in the `LocalizedMessage.message` string,
252221
while also ensuring that the `locale` string shows the correct language.
253222
254-
##### LocalizedMessage payload
223+
#### LocalizedMessage payload
255224
256225
The LocalizedMessage payload **should** contain the complete resolution
257226
to the error. If more information is needed than can fit in this
@@ -293,7 +262,7 @@ descriptions, and examples:
293262
common resolution in the message and use the `Help` payload to
294263
link to relevant documentation.
295264
296-
##### Help payload
265+
#### Help payload
297266
298267
When `LocalizedMessage.message` doesn’t provide the user sufficient
299268
context or actionable next steps, or if there are multiple points of

0 commit comments

Comments
 (0)