try {
DateTime.now().setZone(timeZone) // Throws if invalid
} catch (e: unknown) {
if (e instanceof InvalidDateTimeError){ <--- But there is no place from which we could import `InvalidDateTimeError`
// thrown because of invalid timezone
}
throw e // otherwise propagate
}
Actual vs Expected behavior
Currently we can't tell if an error is InvalidDateTimeError other than some message matching.
Desktop (please complete the following information):
OS: macOS
NodeJS 18
Luxon version 3.3.0
Additional context
Please do let me know if there is some other nice way of distinguishing this error from other errors :) Maybe I'm just missing something!
Describe the bug InvalidDateTimeError is currently private, or more specifically not exported in the @types/luxon. https://github.com/moment/luxon/blob/07023283e74321c2080de9bb73070a3ffd2a7acc/src/errors.js#L11
This change - https://github.com/DefinitelyTyped/DefinitelyTyped/pull/64995 made us want to adopt luxon's strict mode where you set
Settings.throwOnInvalid = true
To Reproduce
This would enable a use case like this:
Actual vs Expected behavior Currently we can't tell if an error is
InvalidDateTimeError
other than some message matching.Desktop (please complete the following information):
Additional context Please do let me know if there is some other nice way of distinguishing this error from other errors :) Maybe I'm just missing something!
ps. ty for the great library!