Skip to content
Snippets Groups Projects
Commit 4b879253 authored by Martin Blanchard's avatar Martin Blanchard
Browse files

_expection.py: Centralise exception declarations

#79
parent 6cc3e5f7
No related branches found
No related tags found
No related merge requests found
Showing
with 46 additions and 80 deletions
......@@ -50,3 +50,27 @@ class ServerError(BgdError):
class BotError(BgdError):
def __init__(self, message, detail=None, reason=None):
super().__init__(message, detail=detail, domain=ErrorDomain.BOT, reason=reason)
class InvalidArgumentError(BgdError):
"""A bad argument was passed, such as a name which doesn't exist."""
def __init__(self, message, detail=None, reason=None):
super().__init__(message, detail=detail, domain=ErrorDomain.SERVER, reason=reason)
class NotFoundError(BgdError):
"""Requested resource not found."""
def __init__(self, message, detail=None, reason=None):
super().__init__(message, detail=detail, domain=ErrorDomain.SERVER, reason=reason)
class OutOfSyncError(BgdError):
"""The worker is out of sync with the server, such as having a differing number of leases."""
def __init__(self, message, detail=None, reason=None):
super().__init__(message, detail=detail, domain=ErrorDomain.SERVER, reason=reason)
class OutOfRangeError(BgdError):
""" ByteStream service read data out of range."""
def __init__(self, message, detail=None, reason=None):
super().__init__(message, detail=detail, domain=ErrorDomain.SERVER, reason=reason)
# Copyright (C) 2018 Bloomberg LP
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# <http://www.apache.org/licenses/LICENSE-2.0>
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from .._exceptions import BgdError, ErrorDomain
class InvalidArgumentError(BgdError):
"""A bad argument was passed, such as a name which doesn't exist.
"""
def __init__(self, message, detail=None, reason=None):
super().__init__(message, detail=detail, domain=ErrorDomain.SERVER, reason=reason)
class NotFoundError(BgdError):
"""Requested resource not found.
"""
def __init__(self, message, detail=None, reason=None):
super().__init__(message, detail=detail, domain=ErrorDomain.SERVER, reason=reason)
class OutofSyncError(BgdError):
"""The worker is out of sync with the server, such as having a differing number of leases.
"""
def __init__(self, message, detail=None, reason=None):
super().__init__(message, detail=detail, domain=ErrorDomain.SERVER, reason=reason)
class OutOfRangeError(BgdError):
""" ByteStream service read data out of range
"""
def __init__(self, message, detail=None, reason=None):
super().__init__(message, detail=detail, domain=ErrorDomain.SERVER, reason=reason)
......@@ -24,11 +24,10 @@ import logging
import grpc
from buildgrid._exceptions import InvalidArgumentError, NotFoundError
from buildgrid._protos.build.bazel.remote.execution.v2 import remote_execution_pb2
from buildgrid._protos.build.bazel.remote.execution.v2 import remote_execution_pb2_grpc
from .._exceptions import InvalidArgumentError, NotFoundError
class ActionCacheService(remote_execution_pb2_grpc.ActionCacheServicer):
......
......@@ -23,7 +23,8 @@ Instance of the Remote Workers interface.
import logging
import uuid
from .._exceptions import InvalidArgumentError, OutofSyncError
from buildgrid._exceptions import InvalidArgumentError, OutOfSyncError
from ..job import LeaseState
......@@ -105,7 +106,7 @@ class BotsInterface:
# TODO: Lease was rejected
raise NotImplementedError("'Not Accepted' is unsupported")
else:
raise OutofSyncError("Server lease: {}. Client lease: {}".format(server_lease, client_lease))
raise OutOfSyncError("Server lease: {}. Client lease: {}".format(server_lease, client_lease))
elif server_state == LeaseState.ACTIVE:
......@@ -118,17 +119,17 @@ class BotsInterface:
return None
else:
raise OutofSyncError("Server lease: {}. Client lease: {}".format(server_lease, client_lease))
raise OutOfSyncError("Server lease: {}. Client lease: {}".format(server_lease, client_lease))
elif server_state == LeaseState.COMPLETED:
raise OutofSyncError("Server lease: {}. Client lease: {}".format(server_lease, client_lease))
raise OutOfSyncError("Server lease: {}. Client lease: {}".format(server_lease, client_lease))
elif server_state == LeaseState.CANCELLED:
raise NotImplementedError("Cancelled states not supported yet")
else:
# Sould never get here
raise OutofSyncError("State now allowed: {}".format(server_state))
raise OutOfSyncError("State now allowed: {}".format(server_state))
return client_lease
......
......@@ -25,11 +25,10 @@ import grpc
from google.protobuf.empty_pb2 import Empty
from buildgrid._exceptions import InvalidArgumentError, OutOfSyncError
from buildgrid._protos.google.devtools.remoteworkers.v1test2 import bots_pb2
from buildgrid._protos.google.devtools.remoteworkers.v1test2 import bots_pb2_grpc
from .._exceptions import InvalidArgumentError, OutofSyncError
class BotsService(bots_pb2_grpc.BotsServicer):
......@@ -69,7 +68,7 @@ class BotsService(bots_pb2_grpc.BotsServicer):
context.set_details(str(e))
context.set_code(grpc.StatusCode.INVALID_ARGUMENT)
except OutofSyncError as e:
except OutOfSyncError as e:
self.logger.error(e)
context.set_details(str(e))
context.set_code(grpc.StatusCode.DATA_LOSS)
......
......@@ -19,11 +19,10 @@ Storage Instances
Instances of CAS and ByteStream
"""
from buildgrid._exceptions import InvalidArgumentError, NotFoundError, OutOfRangeError
from buildgrid._protos.google.bytestream import bytestream_pb2
from buildgrid._protos.build.bazel.remote.execution.v2 import remote_execution_pb2 as re_pb2
from .._exceptions import InvalidArgumentError, NotFoundError, OutOfRangeError
from ...settings import HASH
from buildgrid.settings import HASH
class ContentAddressableStorageInstance:
......
......@@ -26,12 +26,11 @@ import logging
import grpc
from buildgrid._exceptions import InvalidArgumentError, NotFoundError, OutOfRangeError
from buildgrid._protos.google.bytestream import bytestream_pb2, bytestream_pb2_grpc
from buildgrid._protos.build.bazel.remote.execution.v2 import remote_execution_pb2
from buildgrid._protos.build.bazel.remote.execution.v2 import remote_execution_pb2_grpc
from .._exceptions import InvalidArgumentError, NotFoundError, OutOfRangeError
class ContentAddressableStorageService(remote_execution_pb2_grpc.ContentAddressableStorageServicer):
......
......@@ -21,10 +21,10 @@ An instance of the Remote Execution Service.
import logging
from buildgrid._exceptions import InvalidArgumentError
from buildgrid._protos.build.bazel.remote.execution.v2.remote_execution_pb2 import Action
from ..job import Job
from .._exceptions import InvalidArgumentError
class ExecutionInstance:
......
......@@ -26,12 +26,10 @@ from functools import partial
import grpc
from buildgrid._exceptions import InvalidArgumentError
from buildgrid._protos.build.bazel.remote.execution.v2 import remote_execution_pb2_grpc
from buildgrid._protos.google.longrunning import operations_pb2
from .._exceptions import InvalidArgumentError
class ExecutionService(remote_execution_pb2_grpc.ExecutionServicer):
......
......@@ -21,7 +21,7 @@ An instance of the LongRunningOperations Service.
import logging
from .._exceptions import InvalidArgumentError
from buildgrid._exceptions import InvalidArgumentError
class OperationsInstance:
......
......@@ -25,10 +25,9 @@ import grpc
from google.protobuf.empty_pb2 import Empty
from buildgrid._exceptions import InvalidArgumentError
from buildgrid._protos.google.longrunning import operations_pb2_grpc, operations_pb2
from .._exceptions import InvalidArgumentError
class OperationsService(operations_pb2_grpc.OperationsServicer):
......
......@@ -17,11 +17,10 @@ import logging
import grpc
from buildgrid._exceptions import InvalidArgumentError, NotFoundError
from buildgrid._protos.buildstream.v2 import buildstream_pb2
from buildgrid._protos.buildstream.v2 import buildstream_pb2_grpc
from .._exceptions import InvalidArgumentError, NotFoundError
class ReferenceStorageService(buildstream_pb2_grpc.ReferenceStorageServicer):
......
......@@ -24,10 +24,9 @@ For a given key, it
import collections
from buildgrid._exceptions import NotFoundError
from buildgrid._protos.build.bazel.remote.execution.v2 import remote_execution_pb2
from .._exceptions import NotFoundError
class ReferenceCache:
......
......@@ -26,7 +26,7 @@ from collections import deque
from google.protobuf import any_pb2
from buildgrid.server._exceptions import NotFoundError
from buildgrid._exceptions import NotFoundError
from buildgrid._protos.google.longrunning import operations_pb2
from .job import ExecuteStage, LeaseState
......
......@@ -17,10 +17,10 @@
import pytest
from buildgrid._exceptions import NotFoundError
from buildgrid._protos.build.bazel.remote.execution.v2 import remote_execution_pb2
from buildgrid.server.actioncache.storage import ActionCache
from buildgrid.server.cas.storage import lru_memory_cache
from buildgrid.server._exceptions import NotFoundError
from buildgrid._protos.build.bazel.remote.execution.v2 import remote_execution_pb2
@pytest.fixture
......
......@@ -24,12 +24,10 @@ import grpc
from grpc._server import _Context
import pytest
from buildgrid._exceptions import InvalidArgumentError
from buildgrid._protos.build.bazel.remote.execution.v2 import remote_execution_pb2
from buildgrid._protos.google.longrunning import operations_pb2
from buildgrid.server.controller import ExecutionController
from buildgrid.server._exceptions import InvalidArgumentError
from buildgrid.server.operations import service
from buildgrid.server.operations.service import OperationsService
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment