Skip to content

Commit 0a3406d

Browse files
authored
fix: resolves the JSON error when no match is found by comby (fixes #29) (#30)
1 parent c3fd910 commit 0a3406d

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/comby/binary.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,11 @@ def matches(self,
103103
shlex.quote(template), 'foo')
104104
cmd_s = ' '.join(cmd)
105105

106-
jsn = json.loads(self.call(cmd_s, text=source))
107-
jsn = jsn['matches']
108-
for jsn_match in jsn:
109-
yield Match.from_dict(jsn_match)
106+
jsn = json.loads(self.call(cmd_s, text=source) or 'null')
107+
if jsn is not None:
108+
jsn = jsn['matches']
109+
for jsn_match in jsn:
110+
yield Match.from_dict(jsn_match)
110111

111112
def rewrite(self,
112113
source: str,

test/test_binary.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ def test_match(comby):
1818
assert len(matches) == 1
1919
print(matches[0])
2020

21+
def test_no_match(comby):
22+
source = "foo"
23+
template = "bar"
24+
matches = list(comby.matches(source, template))
25+
print(matches)
26+
assert len(matches) == 0
2127

2228
def test_rewrite(comby):
2329
source = "print('hello world')"

0 commit comments

Comments
 (0)