Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Raise UserException when an invalid runtime is specified #6701

Merged
merged 3 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions samcli/local/docker/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,9 @@ class ContainerFailureError(UserException):
"""
Raised when the invoke container fails execution
"""


class InvalidRuntimeException(UserException):
"""
Raised when an invalid runtime is specified for a Lambda Function
"""
4 changes: 3 additions & 1 deletion samcli/local/docker/lambda_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from typing import List

from samcli.lib.utils.packagetype import IMAGE
from samcli.local.docker.exceptions import InvalidRuntimeException
from samcli.local.docker.lambda_debug_settings import LambdaDebugSettings

from .container import DEFAULT_CONTAINER_HOST_INTERFACE, Container
Expand All @@ -15,6 +16,7 @@
LOG = logging.getLogger(__name__)

RIE_LOG_LEVEL_ENV_VAR = "SAM_CLI_RIE_DEV"
INVALID_RUNTIME_MESSAGE = "Unsupported Lambda runtime: {runtime}. For a list of supported runtimes, please visit https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html"


class LambdaContainer(Container):
Expand Down Expand Up @@ -95,7 +97,7 @@ def __init__(
Optional. The function full path, unique in all stacks
"""
if not Runtime.has_value(runtime) and not packagetype == IMAGE:
raise ValueError("Unsupported Lambda runtime {}".format(runtime))
raise InvalidRuntimeException(INVALID_RUNTIME_MESSAGE.format(runtime=runtime))

image = LambdaContainer._get_image(
lambda_image, runtime, packagetype, imageuri, layers, architecture, function_full_path
Expand Down
8 changes: 6 additions & 2 deletions tests/unit/local/docker/test_lambda_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from samcli.commands.local.lib.debug_context import DebugContext
from samcli.lib.utils.packagetype import IMAGE, ZIP
from samcli.local.docker.exceptions import InvalidRuntimeException
from samcli.local.docker.lambda_container import LambdaContainer, Runtime, RIE_LOG_LEVEL_ENV_VAR
from samcli.local.docker.lambda_debug_settings import DebuggingNotSupported
from samcli.local.docker.lambda_image import RAPID_IMAGE_TAG_PREFIX
Expand Down Expand Up @@ -433,7 +434,7 @@ def test_must_fail_for_unsupported_runtime(self):

image_builder_mock = Mock()

with self.assertRaises(ValueError) as context:
with self.assertRaises(InvalidRuntimeException) as context:
LambdaContainer(
runtime=runtime,
imageuri=self.imageuri,
Expand All @@ -446,7 +447,10 @@ def test_must_fail_for_unsupported_runtime(self):
architecture="x86_64",
)

self.assertEqual(str(context.exception), "Unsupported Lambda runtime foo")
self.assertEqual(
str(context.exception),
"Unsupported Lambda runtime: foo. For a list of supported runtimes, please visit https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html",
)

@parameterized.expand(
[
Expand Down
Loading