Closed glaszig closed 5 years ago
just realized we‘re gonna need the same for DateTime
. will add that later.
renamed Date::DateError
to Date::InvalidDateError
. added an analogous DateTime::InvalidDateTimeError
. i think those are better names and having one per "module" is the better way.
How about ParseError
I thought a bit more about this.
You probably want to introduce the following:
class Date::Error < StandardError
end
class Date::ParseError < Date::Error
end
class DateTime::ParseError < DateTime::ParseError
end
There are probably other ways to structure it but the key point is:
that’s fine with me. what about compatibility, code that expects ArgumentError
?
Maybe it should just be ParseError < ArgumentError?
fine with me as well. makes more sense, too. done.
This appears to use Date::ParseError
/DateTime::ParseError
in cases where there is no parsing, which I think is confusing. Date::Error
or Date::InvalidDateError
both seem like better names. I don't think an error specific to date parsing is worth adding.
I would actually just add Date::Error < ArgumentError
. DateTime::Error
would refer to it as DateTime
subclasses Date
. I don't think there is a need to separate Date
errors from DateTime
errors, and if there is a need in the future, it is easy to make DateTime::Error < Date::Error
.
I would actually just add Date::Error < ArgumentError. DateTime::Error would refer to it as DateTime subclasses Date
done. do you see other raise
s that need to be adjusted? i'm not exactly sure.
I think every place that raises ArgumentError with invalid *
messages should probably be converted to Date::Error
. There appears to be some cases that still need to be updated.
I think every place that raises ArgumentError with invalid * messages should probably be converted to Date::Error. There appears to be some cases that still need to be updated.
done. rebase + fixup?
This looks good to me. Assuming no objections, I plan to merge it before the release of Ruby 2.7.
thanks. i‘ll rebase + fixup this weekend.
all too often i see and write the following:
with this patch this code will still work (because
Date::InvalidDateError < ArgumentError
) but can become this:i think
ArgumentError
is far too generic for the case of failing because of an invalid date and we are dealing with dates quite often. that's why i want to introduce a more specific error type to make it easier to target that case in code bases and not running the risk of rescuing unrelatedArgumentError
's withrescue ArgumentError
when actually just wanting to deal with an invalid date that we get from user-input.there also is a
DateTime::InvalidDateTimeError
class which works exactly the same:what do you think?