Skip to content
Open
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: 3 additions & 3 deletions samcli/lib/sync/watch_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from samcli.lib.utils.colors import Colored, Colors
from samcli.lib.utils.path_observer import HandlerObserver
from samcli.lib.utils.resource_trigger import OnChangeCallback, TemplateTrigger
from samcli.local.lambdafn.exceptions import ResourceNotFound
from samcli.local.lambdafn.exceptions import FunctionNotFound, ResourceNotFound

if TYPE_CHECKING: # pragma: no cover
from samcli.commands.build.build_context import BuildContext
Expand Down Expand Up @@ -152,10 +152,10 @@ def _add_code_triggers(self) -> None:
extra=dict(markup=True),
)
continue
except ResourceNotFound:
except (ResourceNotFound, FunctionNotFound):
LOG.warning(
self._color.color_log(
msg="CodeTrigger not created as %s is not found or is with a S3 Location.",
msg="CodeTrigger not created as %s is not found or is with a remote location (S3/ECR).",
color=Colors.WARNING,
),
str(resource_id),
Expand Down
27 changes: 26 additions & 1 deletion tests/unit/lib/sync/test_watch_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from samcli.lib.sync.exceptions import MissingPhysicalResourceError, SyncFlowException
from parameterized import parameterized

from samcli.local.lambdafn.exceptions import ResourceNotFound
from samcli.local.lambdafn.exceptions import FunctionNotFound, ResourceNotFound


class TestWatchManager(TestCase):
Expand Down Expand Up @@ -106,6 +106,31 @@ def test_add_code_triggers(self, get_all_resource_ids_mock, patched_log):
self.path_observer.schedule_handlers.assert_any_call(trigger_2.get_path_handlers.return_value)
self.assertEqual(self.path_observer.schedule_handlers.call_count, 2)

@patch("samcli.lib.sync.watch_manager.LOG")
@patch("samcli.lib.sync.watch_manager.get_all_resource_ids")
def test_add_code_triggers_function_not_found(self, get_all_resource_ids_mock, patched_log):
"""Test that FunctionNotFound is handled gracefully for ECR-based image functions"""
resource_ids = [MagicMock(), MagicMock()]
get_all_resource_ids_mock.return_value = resource_ids

trigger_1 = MagicMock()

trigger_factory = MagicMock()
trigger_factory.create_trigger.side_effect = [
trigger_1,
FunctionNotFound(),
]
self.watch_manager._stacks = [MagicMock()]
self.watch_manager._trigger_factory = trigger_factory

on_code_change_wrapper_mock = MagicMock()
self.watch_manager._on_code_change_wrapper = on_code_change_wrapper_mock

self.watch_manager._add_code_triggers()

# Should only schedule handlers for the first trigger, not the FunctionNotFound one
self.path_observer.schedule_handlers.assert_called_once_with(trigger_1.get_path_handlers.return_value)

@patch("samcli.lib.sync.watch_manager.TemplateTrigger")
@patch("samcli.lib.sync.watch_manager.SamLocalStackProvider.get_stacks")
def test_add_template_triggers(self, get_stack_mock, template_trigger_mock):
Expand Down
Loading