1# Copyright 2014 Google LLC
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15# pylint: disable=invalid-name
16# pylint recognizies all of these aliases as constants and thinks they have
17# invalid names.
18
19"""Custom exceptions for :mod:`google.cloud` package."""
20
21# Avoid the grpc and google.cloud.grpc collision.
22from __future__ import absolute_import
23
24from typing import Set
25
26# PEP 0810: Explicit Lazy Imports
27# Python 3.15+ natively intercepts and defers these imports.
28# Developers can disable this behavior and force eager imports.
29# For more information, see:
30# https://docs.python.org/3.15/library/sys.html#sys.set_lazy_imports_filter
31# Older Python versions safely ignore this variable.
32# NOTE: We statically define all modules here to ensure static analysis tools
33# (mypy, pyright, Ruff) can easily parse them. If support is not present, the
34# imports are ignored, making their presence safe.
35__lazy_modules__: Set[str] = {
36 "google.api_core.exceptions",
37 "grpc",
38 "grpc._channel",
39}
40
41from google.api_core import exceptions
42
43try:
44 from grpc._channel import _Rendezvous
45except ImportError: # pragma: NO COVER
46 _Rendezvous = None
47
48GrpcRendezvous = _Rendezvous
49"""Exception class raised by gRPC stable."""
50
51# Aliases to moved classes.
52GoogleCloudError = exceptions.GoogleAPICallError
53Redirection = exceptions.Redirection
54MovedPermanently = exceptions.MovedPermanently
55NotModified = exceptions.NotModified
56TemporaryRedirect = exceptions.TemporaryRedirect
57ResumeIncomplete = exceptions.ResumeIncomplete
58ClientError = exceptions.ClientError
59BadRequest = exceptions.BadRequest
60Unauthorized = exceptions.Unauthorized
61Forbidden = exceptions.Forbidden
62NotFound = exceptions.NotFound
63MethodNotAllowed = exceptions.MethodNotAllowed
64Conflict = exceptions.Conflict
65LengthRequired = exceptions.LengthRequired
66PreconditionFailed = exceptions.PreconditionFailed
67RequestRangeNotSatisfiable = exceptions.RequestRangeNotSatisfiable
68TooManyRequests = exceptions.TooManyRequests
69ServerError = exceptions.ServerError
70InternalServerError = exceptions.InternalServerError
71MethodNotImplemented = exceptions.MethodNotImplemented
72BadGateway = exceptions.BadGateway
73ServiceUnavailable = exceptions.ServiceUnavailable
74GatewayTimeout = exceptions.GatewayTimeout
75from_http_status = exceptions.from_http_status
76from_http_response = exceptions.from_http_response