Skip to content
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
11 changes: 8 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
name: Release
on:
pull_request:
branches:
- main
branches: [main]
types: [closed]
permissions:
contents: write
Expand All @@ -11,10 +10,16 @@ jobs:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- name: Create GitHub App token
id: app-token
uses: actions/create-github-app-token@v2
with:
app-id: ${{ vars.RELEASE_APP_ID }}
private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }}
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
token: ${{ steps.app-token.outputs.token }}
- name: Install uv
uses: astral-sh/setup-uv@v6
- name: Install the project
Expand Down
18 changes: 14 additions & 4 deletions packages/asyncfast/src/asyncfast/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@
_PARAMETER_PATTERN = re.compile(r"{(.*)}")


class InvalidChannelDefinitionError(ValueError):
"""
Raised when a channel or message handler is defined with an invalid shape.
"""


async def _send_message(send: AMGISendCallable, message: Mapping[str, Any]) -> None:
message_send_event: MessageSendEvent = {
"type": "message.send",
Expand Down Expand Up @@ -323,13 +329,17 @@ def _add_channel(
elif _is_message(message_sender_type):
messages = [message_sender_type]

assert len(payloads) <= 1, "Channel must have no more than 1 payload"
if len(payloads) > 1:
raise InvalidChannelDefinitionError(
"Channel must have no more than 1 payload"
)

payload = payloads[0] if len(payloads) == 1 else None

assert (
len(message_senders) <= 1
), "Channel must have no more than 1 message sender"
if len(message_senders) > 1:
raise InvalidChannelDefinitionError(
"Channel must have no more than 1 message sender"
)

message_sender = message_senders[0] if len(message_senders) == 1 else None

Expand Down
29 changes: 29 additions & 0 deletions packages/asyncfast/tests_asyncfast/test_errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from typing import Any

import pytest
from asyncfast import AsyncFast
from asyncfast import InvalidChannelDefinitionError
from asyncfast import MessageSender


async def test_only_one_payload() -> None:
app = AsyncFast()

with pytest.raises(InvalidChannelDefinitionError):

@app.channel("topic")
async def topic_handler(payload1: int, payload2: int) -> None:
pass # pragma: no cover


async def test_only_one_message_sender() -> None:
app = AsyncFast()

with pytest.raises(InvalidChannelDefinitionError):

@app.channel("topic")
async def topic_handler(
message_sender1: MessageSender[dict[str, Any]],
message_sender2: MessageSender[dict[str, Any]],
) -> None:
pass # pragma: no cover