Skip to content

Commit

Permalink
CommandLineRunner is extremely sensitive to argument order
Browse files Browse the repository at this point in the history
It will fail in strange ways unless the file URIs *precede* all of the other
arguments, including --raw.
  • Loading branch information
dlenski committed Sep 21, 2023
1 parent 847e180 commit 359e16a
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions zxing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def decode(self, filenames, try_harder=False, possible_formats=None, pure_barcod
fn = fn_or_im
file_uris.append(pathlib.Path(fn).absolute().as_uri())

cmd = [self.java, '-cp', self.classpath, self.cls]
cmd = [self.java, '-cp', self.classpath, self.cls] + file_uris
if self.zxing_version_info and self.zxing_version_info >= (3, 5, 0):
cmd.append('--raw')
if try_harder:
Expand All @@ -97,7 +97,6 @@ def decode(self, filenames, try_harder=False, possible_formats=None, pure_barcod
if possible_formats:
for pf in possible_formats:
cmd += ['--possible_formats', pf]
cmd += file_uris

try:
p = sp.Popen(cmd, stdout=sp.PIPE, stderr=sp.STDOUT, universal_newlines=False)
Expand Down Expand Up @@ -129,7 +128,7 @@ def decode(self, filenames, try_harder=False, possible_formats=None, pure_barcod
fn = file_uri_to_path(stdout.splitlines()[0][63:].decode())
raise BarCodeReaderException("Java library could not read image (is it in a supported format?)", fn)
elif stdout.startswith(b'''Exception '''):
raise BarCodeReaderException("Unknown Java exception", self.java) from RuntimeError(stdout)
raise BarCodeReaderException("Unknown Java exception", self.java) from sp.CalledProcessError(0, cmd, stdout)
elif p.returncode:
raise BarCodeReaderException("Unexpected Java subprocess return code", self.java) from sp.CalledProcessError(p.returncode, cmd, stdout)

Expand Down

0 comments on commit 359e16a

Please sign in to comment.