confuse icon indicating copy to clipboard operation
confuse copied to clipboard

`Configuration.dump` raises `StopIteration` if the last line is empty.

Open tkorvola opened this issue 3 years ago • 3 comments

yaml_util.restore_yaml_comments has an explicit call to next without catching StopIteration, which is raised if the last processed line is empty or a comment. This seems to happen in Configuration.dump if the last line of config_default.yaml is empty or a comment.

tkorvola avatar Jun 20 '22 10:06 tkorvola

Aha, that's annoying! Any chance you have a test input you could provide so we can craft a fix and a test to make sure we don't reintroduce this?

sampsyo avatar Jun 22 '22 12:06 sampsyo

Try putting this in config_default.yaml:

foo: 42
# Oops.

tkorvola avatar Jun 22 '22 20:06 tkorvola

Thanks!!

It turns out that writing tests for this is surprisingly annoying, given the hard-coded way we have of relying on the default source to exclude default options. I gave it a start in the test-dump branch: https://github.com/beetbox/confuse/tree/test-dump

…but in case anyone is following along here, I would love some help bringing this to completion so we can test for this behavior.

Also worth noting that #52 could hopefully sidestep this by switching to a proper/robust round-tripping YAML library…

sampsyo avatar Jun 23 '22 15:06 sampsyo