Skip to content

Commit

Permalink
renamed exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderegg committed Aug 15, 2024
1 parent c6c637d commit 7494359
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,18 @@ class ConfigurationError(AutoscalingRuntimeError):
msg_template: str = "Application misconfiguration: {msg}"


class Ec2InstanceInvalidError(AutoscalingRuntimeError):
msg_template: str = "Invalid EC2 defined: {msg}"
class TaskRequiresUnauthorizedEC2InstanceTypeError(AutoscalingRuntimeError):
msg_template: str = (
"Task {task} requires unauthorized {instance_type}. "
"TIP: check task required instance type or allow the instance type in autoscaling service settings"
)


class TaskRequirementsAboveRequiredEC2InstanceTypeError(AutoscalingRuntimeError):
msg_template: str = (
"Task {task} requires {instance_type} but requires {resources}. "
"TIP: Ensure task resources requirements fit required instance type available resources."
)


class Ec2InvalidDnsNameError(AutoscalingRuntimeError):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
from models_library.generated_models.docker_rest_api import Node
from types_aiobotocore_ec2.literals import InstanceTypeType

from ..core.errors import Ec2InstanceInvalidError, Ec2InvalidDnsNameError
from ..core.errors import (
Ec2InvalidDnsNameError,
TaskRequirementsAboveRequiredEC2InstanceTypeError,
TaskRequiresUnauthorizedEC2InstanceTypeError,
)
from ..core.settings import ApplicationSettings
from ..models import AssociatedInstance
from ..modules.auto_scaling_mode_base import BaseAutoscaling
Expand Down Expand Up @@ -142,11 +146,9 @@ def find_selected_instance_type_for_task(
)
)
if not filtered_instances:
msg = (
f"Task {task} requires an unauthorized EC2 instance type."
f"Asked for {instance_type_name}, authorized are {available_ec2_types}. Please check!"
raise TaskRequiresUnauthorizedEC2InstanceTypeError(
task=task, instance_type=instance_type_name
)
raise Ec2InstanceInvalidError(msg=msg)

assert len(filtered_instances) == 1 # nosec
selected_instance = filtered_instances[0]
Expand All @@ -156,11 +158,11 @@ def find_selected_instance_type_for_task(
auto_scaling_mode.get_task_required_resources(task)
> selected_instance.resources
):
msg = (
f"Task {task} requires more resources than the selected instance provides."
f" Asked for {selected_instance}, but task needs {auto_scaling_mode.get_task_required_resources(task)}. Please check!"
raise TaskRequirementsAboveRequiredEC2InstanceTypeError(
task=task,
instance_type=selected_instance,
resources=auto_scaling_mode.get_task_required_resources(task),
)
raise Ec2InstanceInvalidError(msg=msg)

return selected_instance

Expand Down

0 comments on commit 7494359

Please sign in to comment.