# Buggy code
def single_line_to_path(line: np.ndarray) -> str:
    if line[0] == line[-1]:
        closed = True
        line = line[:-1]
    else:
        closed = False
    return (
        "M"
        + " L".join(f"{x},{y}" for x, y in as_vector(line))
        + (" Z" if closed else "")
    )


# Traceback (IndexError)
Traceback (most recent call last):
File "/Users/theuser/.pyenv/versions/plotter/bin/vpype", line 8, in <module>
sys.exit(cli())
File "/Users/theuser/.pyenv/versions/3.7.7/envs/plotter/lib/python3.7/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/Users/theuser/.pyenv/versions/3.7.7/envs/plotter/lib/python3.7/site-packages/vpype_cli/cli.py", line 72, in main
return super().main(args=preprocess_argument_list(args), **extra)
File "/Users/theuser/.pyenv/versions/3.7.7/envs/plotter/lib/python3.7/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/Users/theuser/.pyenv/versions/3.7.7/envs/plotter/lib/python3.7/site-packages/click/core.py", line 1290, in invoke
return _process_result(rv)
File "/Users/theuser/.pyenv/versions/3.7.7/envs/plotter/lib/python3.7/site-packages/click/core.py", line 1224, in _process_result
value = ctx.invoke(self.result_callback, value, **ctx.params)
File "/Users/theuser/.pyenv/versions/3.7.7/envs/plotter/lib/python3.7/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/Users/theuser/.pyenv/versions/3.7.7/envs/plotter/lib/python3.7/site-packages/vpype_cli/cli.py", line 118, in process_pipeline
execute_processors(processors)
File "/Users/theuser/.pyenv/versions/3.7.7/envs/plotter/lib/python3.7/site-packages/vpype_cli/cli.py", line 202, in execute_processors
state = proc(state)
File "/Users/theuser/.pyenv/versions/3.7.7/envs/plotter/lib/python3.7/site-packages/vpype/decorators.py", line 154, in global_processor
state.vector_data = f(state.vector_data, *args, **kwargs)
File "/Users/theuser/.pyenv/versions/3.7.7/envs/plotter/lib/python3.7/site-packages/vpype_cli/read.py", line 106, in read
read_svg(file, quantization=quantization, simplify=not no_simplify),
File "/Users/theuser/.pyenv/versions/3.7.7/envs/plotter/lib/python3.7/site-packages/vpype/io.py", line 163, in read_svg
doc.flatten_all_paths(), quantization, scale_x, scale_y, offset_x, offset_y, simplify,
File "/Users/theuser/.pyenv/versions/3.7.7/envs/plotter/lib/python3.7/site-packages/svgpathtools/document.py", line 219, in flatten_all_paths
path_filter, path_conversions)
File "/Users/theuser/.pyenv/versions/3.7.7/envs/plotter/lib/python3.7/site-packages/svgpathtools/document.py", line 142, in flatten_all_paths
path = transform(parse_path(converter(path_elem)), path_tf)
File "/Users/theuser/.pyenv/versions/3.7.7/envs/plotter/lib/python3.7/site-packages/svgpathtools/parser.py", line 91, in parse_path
segments.closed = True
File "/Users/theuser/.pyenv/versions/3.7.7/envs/plotter/lib/python3.7/site-packages/svgpathtools/path.py", line 2241, in closed
if value and not self._is_closable():
File "/Users/theuser/.pyenv/versions/3.7.7/envs/plotter/lib/python3.7/site-packages/svgpathtools/path.py", line 2219, in _is_closable
end = self[-1].end
File "/Users/theuser/.pyenv/versions/3.7.7/envs/plotter/lib/python3.7/site-packages/svgpathtools/path.py", line 2081, in __getitem__
return self._segments[index]
IndexError: list index out of range

# Fixed code
def single_line_to_path(line: np.ndarray) -> str:
    if line[0] == line[-1] and len(line) > 2:
        closed = True
        line = line[:-1]
    else:
        closed = False
    return (
        "M"
        + " L".join(f"{x},{y}" for x, y in as_vector(line))
        + (" Z" if closed else "")
    )