tinytoml icon indicating copy to clipboard operation
tinytoml copied to clipboard

Check state of input stream before parsing

Open DoumanAsh opened this issue 8 years ago • 1 comments

Currently passing failed/bad stream results in successful parsing(which actually parses nothing at all).

Simple case would be pass ifstream to non-existing fail

std::ifstream ifs("foo.toml");
toml::ParseResult pr = toml::parse(ifs);

if (!pr.valid()) {
    cout << pr.errorReason << endl;
    return;
}

It is a bit tricky as it should be up to user to provide a valid output. But on other hand there is no way it would be possible parse failed/bad stream.

What do you think? Should there be error on such cases?

DoumanAsh avatar Nov 04 '17 12:11 DoumanAsh

@DoumanAsh Thanks for reporting... Yeah, I think it's not good. It should be an error. I'll fix it.

mayah avatar Nov 05 '17 03:11 mayah