PerMalmberg/libcron

Format validation

Closed this issue · 6 comments

Tectu commented

The readme specifies the support format.
Is there functionality available as part of the library, that allows to check whether a provided cron-string is formatted in a valid manner? If not - any plans on the roadmap to add this feature?

The library verifies the input string and that it can calculate a valid time point based of it. There are numerous of tests showing this, is there something you're missing?

Tectu commented

Based on your answer I take it that add_schedule() performs the validation, correct?
What happens if an invalid format is detected? Will the task be discarded silently? Is there an error code? Exception?

is there something you're missing?

I assume the corresponding part of the documentation - unless I am blind :p

Tectu commented

I take it that the example snipped:

auto res = c1.add_schedule(name_schedule_map, [](auto&) { });
if (std::get<0>(res) == false)
{
	std::cout << "Task " << std::get<1>(res) 
						<< "has an invalid schedule: " 
						<< std::get<2>(res) << std::endl;
}

is of relevance here?

However, this is shown under the section Adding multiple tasks with individual schedules at once.

Yes, add_schedule will return a bool indicating if the schedule was added/validated. Might not be explicitly documented, but I'd say the API is pretty clear if you take the time to read it.

Tectu commented

So to circle back: There is no way of knowing why add_schedule() failed and therefore no way to know for me, as a user of the library, whether it failed because the format is invalid?

I am looking for a way to explicitly check the format for validation in order to provide the user of the software with means of figuring out what went wrong (-> eg. wrong/invalid cron format supplied to your library).

Oh, so that's what you're asking for. No, the library doesn't expose that kind of information. I don't think it'd be very hard to add, feel free to make a PR.