gRPC

gRPC 2 UNKNOWN vs 9 FAILED_PRECONDITION

Both gRPC 2 (UNKNOWN) and 9 (FAILED_PRECONDITION) belong to the gRPC Status Codes category. 2 indicates that an unknown error occurred. This may be returned when a server raises an exception that doesn't map to any known gRPC status code. Meanwhile, 9 means that the operation was rejected because the system is not in a state required for the operation's execution. For example, deleting a non-empty directory.

説明

An unknown error occurred. This may be returned when a server raises an exception that doesn't map to any known gRPC status code.

このコードが表示される場合

The server threw an unhandled exception or returned an error that gRPC couldn't classify into a more specific status code.

解決方法

Check the server logs for the underlying exception. Wrap server-side errors with explicit gRPC status codes instead of letting them bubble up as UNKNOWN.

説明

The operation was rejected because the system is not in a state required for the operation's execution. For example, deleting a non-empty directory.

このコードが表示される場合

The request is valid on its own, but the system's current state doesn't allow it — like trying to delete a non-empty directory or update a resource that has been modified concurrently.

解決方法

Bring the system into the required state before retrying. For example, empty the directory first, or re-read the resource to get the latest version before updating.

主な違い

1.

gRPC 2: An unknown error occurred. This may be returned when a server raises an exception that doesn't map to any known gRPC status code.

2.

gRPC 9: The operation was rejected because the system is not in a state required for the operation's execution. For example, deleting a non-empty directory.

3.

You encounter 2 when the server threw an unhandled exception or returned an error that gRPC couldn't classify into a more specific status code.

4.

You encounter 9 when the request is valid on its own, but the system's current state doesn't allow it — like trying to delete a non-empty directory or update a resource that has been modified concurrently.

どちらをいつ使うか

For 2 (UNKNOWN): Check the server logs for the underlying exception. Wrap server-side errors with explicit gRPC status codes instead of letting them bubble up as UNKNOWN. For 9 (FAILED_PRECONDITION): Bring the system into the required state before retrying. For example, empty the directory first, or re-read the resource to get the latest version before updating.

詳しく見る