open-simulation-platform / libcosim

OSP C++ co-simulation library

Home Page:https://open-simulation-platform.github.io/libcosim

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Incosistent use of error feedback in consume scheme

THEvang opened this issue · comments

Consume scheme uses both exceptions and nullopts to signal an erroneous scheme and I think we should stick to one of them. I would prefer nullopt.

I also don't think it throws if the scheme is empty.

If pos is to be zero, then it must never increase. That happens for instance if we give an empty input. However, then pos == input.size() because both pos and input size is zero, thereby triggering the first if branch returning nullopts.

If we give an non-empty string with an empty scheme such as "://example.com", then the scheme is empty, but the scheme empty exception is not thrown because inputs[pos] == : since pos is never increased because : is not a scheme character.

The other way is if we give a weird scheme like ////: because / is not an alphanumeric character. Then, the exception is thrown, not because the scheme is empty, but because it is invalid.

throw std::invalid_argument("URI scheme is empty");

The use of both exceptions and nullopts is by design. The intent is that it should return a nullopt if the given string doesn't contain any scheme (in which case it's a relative URI reference, not an absolute URI), and that it should throw if there appears to be a scheme but it's empty.

It looks to me like it will throw on a string like ://example.com. Did you test it?

You are correct. I misread != as == in the first if branch.