Mossop / glowmarkt-rs

A crate for accessing the Glowmarkt API
MIT License
2 stars 1 forks source link

Very poor error message when an unexpected date format is passed on the command line #1

Closed jnioche closed 8 months ago

jnioche commented 8 months ago

Thanks for sharing your code. It is great to be able to query the data from the command line. I am getting an error message when trying to retrieve the readings

glowmarkt  -u $GLOWMARKT_USER  -p $GLOWMARKT_PWD readings a1685621-8196-441a-a722-dc10c9abceb8 2023-01-01
Error: "the `Parsed` struct did not include enough information to construct the type"

I am only starting programming in RUST so not quite able to work out what the problem is.

BTW I had to do

sudo apt install libssl-dev

in order to build the program. Maybe it would be worth mentioning it in the README?

Thanks!

Mossop commented 8 months ago

Thanks for the report. This is a rather lousy error message for it failing to understand the date on the command line. Currently you either have to pass a full ISO8601 date and time (something like 2023-01-01T00:00:00Z) or a negative number of minutes (say -1440) which will subtracted from the current time. It would be nice to improve the date handling and the documentation here.

jnioche commented 8 months ago

I had tried '2023-01-01T00:00:00' so was just one Z short. Thanks for the explanation, just tried and it works fine. I'll see if I can understand what the code does and contribute a PR.

Mossop commented 8 months ago

Should you want to attempt to fix the error messages the thing to do would be to replace the calls that currently map the error from the time crate into strings, here and here with something a little more helpful:

.map_err(|_| format!("Couldn't the date format '{date}', ... some helpful"))

I also filed #4 for the specific case you attempted which seems useful to support.

jnioche commented 8 months ago

Thanks @Mossop I really need to up my skills in Rust. FYI I am planning to write a library to facilitate querying the UK Carbon Intensity API. Ideally, this could then help enrich the data coming from Glowmarkt by giving an accurate estimate of the CO2 emissions for a user, based not on some generic average figure but on the actual carbon intensity in the region at the time of consumption.

Mossop commented 8 months ago

Sounds like a useful project and the best way to learn is by doing! I'm by no means a Rust expert myself.

jnioche commented 8 months ago

Should you want to attempt to fix the error messages the thing to do would be to replace the calls that currently map the error from the time crate into strings, here and here with something a little more helpful:

.map_err(|_| format!("Couldn't the date format '{date}', ... some helpful"))

Implemented, see #5