Page MenuHomeSoftware Heritage

Improve date parsing error messages
Closed, MigratedEdits Locked

Event Timeline

olasd changed the visibility from "All Users" to "Public (No Login Required)".May 13 2016, 5:08 PM

From discussion with @ardumont, this is only about the utils.py parse_timestamp function, to receive date inputs from users.

We have python3-dateutil version 2.4.2, which constructs the result from defaults even if nothing in the string matched - this means that we can't differentiate a request for the default and a parser failure. Version 2.5.0 fixes this to return a ValueError if the parsing fails.

Additionally, while attempting to see if the input is a POSIX timestamp in case of failure, we should also catch a conversion error and return an exception with a more verbose/descriptive message.

jbertran reopened this task as Open.
jbertran claimed this task.
jbertran lowered the priority of this task from Normal to Low.

This function was rewritten, its actual behavior no longer matches what's described by @jbertran, that is:

  • if the timestamp is None, return None directly (it's up to the caller to do something appropriate with that)
  • Otherwise, try to parse it, if successful, returns the resulting datetime
  • Otherwise, assume the date passed is a timestamp and try to determine the date from that, if ok, return the datetime
  • Otherwise, throws a BadInputExc with the original error (which renders a 400, bad request to the api caller).
ardumont removed jbertran as the assignee of this task.