Skip to content

Commit 7545424

Browse files
bokelleyclaude
andauthored
feat(translation): list known keys in TranslationMap KeyError (#768)
* feat(translation): list known keys in TranslationMap KeyError messages When `to_upstream` / `to_adcp` miss, surface the full set of known keys in the exception so adopters debugging a typo or stale mapping see the fix without instrumenting the call site. dx-expert flagged this as the one outstanding nit from the #453 triage; the rest of that issue is resolved by #464. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * ci: skip merge commits from remote-tracking refs `git merge origin/main` produces "Merge remote-tracking branch 'origin/main' …", which the conventional-commits skip regex didn't match — only `Merge branch '<name>'` was covered. Validator then flagged the merge commit as a malformed conventional commit and failed the check. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent e7c0815 commit 7545424

3 files changed

Lines changed: 21 additions & 7 deletions

File tree

.github/workflows/ci.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,14 @@ jobs:
114114
# Check each commit since the base
115115
echo "Validating commits since $BASE_SHA..."
116116
git log --format="%H %s" $BASE_SHA..HEAD | while read sha message; do
117-
# Skip merge commits. Two GitHub-created shapes:
117+
# Skip merge commits. Three GitHub/git-created shapes:
118118
# - "Merge <sha> into <sha>" — the merge-queue API path
119119
# (clicking "Update branch" on a PR)
120120
# - "Merge branch '<name>' [into <name>]" — `gh pr update-branch`
121-
# and `git merge` defaults
122-
if echo "$message" | grep -qE "^Merge ([0-9a-f]+ into [0-9a-f]+|branch '[^']+')"; then
121+
# and `git merge <local-branch>` defaults
122+
# - "Merge remote-tracking branch '<name>' [into <name>]" —
123+
# `git merge origin/<branch>` default
124+
if echo "$message" | grep -qE "^Merge ([0-9a-f]+ into [0-9a-f]+|(remote-tracking )?branch '[^']+')"; then
123125
echo "⊙ Skipping merge commit: $sha"
124126
continue
125127
fi

src/adcp/decisioning/translation.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ def to_upstream(self, adcp_key: A) -> U:
8181
return self._forward[adcp_key]
8282
if self._default_upstream is not None:
8383
return self._default_upstream
84-
raise KeyError(f"unknown AdCP key: {adcp_key!r}")
84+
known = sorted(self._forward.keys(), key=repr)
85+
raise KeyError(f"unknown AdCP key {adcp_key!r}; known keys: {known!r}")
8586

8687
def to_adcp(self, upstream_key: U) -> A:
8788
"""Translate an upstream platform value back to the AdCP wire value.
@@ -93,7 +94,8 @@ def to_adcp(self, upstream_key: U) -> A:
9394
return self._reverse[upstream_key]
9495
if self._default_adcp is not None:
9596
return self._default_adcp
96-
raise KeyError(f"unknown upstream key: {upstream_key!r}")
97+
known = sorted(self._reverse.keys(), key=repr)
98+
raise KeyError(f"unknown upstream key {upstream_key!r}; known keys: {known!r}")
9799

98100
def has_adcp(self, value: object) -> bool:
99101
"""True when ``value`` is a known AdCP-side key."""

tests/test_upstream_helpers.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,22 @@ def test_to_adcp_returns_a_side(self) -> None:
5858
assert self.channel_map.to_adcp("audio") == "streaming_audio"
5959

6060
def test_to_upstream_raises_on_unknown(self) -> None:
61-
with pytest.raises(KeyError):
61+
with pytest.raises(KeyError) as exc_info:
6262
self.channel_map.to_upstream("unknown")
63+
message = str(exc_info.value)
64+
assert "'unknown'" in message
65+
assert "'olv'" in message
66+
assert "'ctv'" in message
67+
assert "'display'" in message
68+
assert "'streaming_audio'" in message
6369

6470
def test_to_adcp_raises_on_unknown(self) -> None:
65-
with pytest.raises(KeyError):
71+
with pytest.raises(KeyError) as exc_info:
6672
self.channel_map.to_adcp("unknown_upstream")
73+
message = str(exc_info.value)
74+
assert "'unknown_upstream'" in message
75+
assert "'video'" in message
76+
assert "'audio'" in message
6777

6878
def test_has_adcp(self) -> None:
6979
assert self.channel_map.has_adcp("olv") is True

0 commit comments

Comments
 (0)