feat(cron): proper parse error handling
parent
86e519a185
commit
d6b7ce98c1
|
@ -28,6 +28,24 @@ struct C.cron_simple_time {
|
||||||
|
|
||||||
type SimpleTime = C.cron_simple_time
|
type SimpleTime = C.cron_simple_time
|
||||||
|
|
||||||
|
enum ParseError as u8 {
|
||||||
|
ok = 0
|
||||||
|
invalid_expression = 1
|
||||||
|
invalid_number = 2
|
||||||
|
out_of_range = 3
|
||||||
|
too_many_parts = 4
|
||||||
|
}
|
||||||
|
|
||||||
|
fn (e ParseError) str() string {
|
||||||
|
return match e {
|
||||||
|
.ok { '' }
|
||||||
|
.invalid_expression { 'Invalid expression' }
|
||||||
|
.invalid_number { 'Invalid number' }
|
||||||
|
.out_of_range { 'Out of range' }
|
||||||
|
.too_many_parts { 'Too many parts' }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn C.ce_init() &C.cron_expression
|
fn C.ce_init() &C.cron_expression
|
||||||
|
|
||||||
fn C.ce_free(ce &C.cron_expression)
|
fn C.ce_free(ce &C.cron_expression)
|
||||||
|
@ -36,4 +54,4 @@ fn C.ce_next(out &C.cron_simple_time, ce &C.cron_expression, ref &C.cron_simple_
|
||||||
|
|
||||||
fn C.ce_next_from_now(out &C.cron_simple_time, ce &C.cron_expression)
|
fn C.ce_next_from_now(out &C.cron_simple_time, ce &C.cron_expression)
|
||||||
|
|
||||||
fn C.ce_parse_expression(out &C.cron_expression, s &char) int
|
fn C.ce_parse_expression(out &C.cron_expression, s &char) ParseError
|
||||||
|
|
|
@ -11,7 +11,7 @@ pub fn parse_expression(exp string) !&Expression {
|
||||||
out := C.ce_init()
|
out := C.ce_init()
|
||||||
res := C.ce_parse_expression(out, exp.str)
|
res := C.ce_parse_expression(out, exp.str)
|
||||||
|
|
||||||
if res != 0 {
|
if res != .ok {
|
||||||
return error(res.str())
|
return error(res.str())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue