route_exist returns both bool and err-msg now

This commit is contained in:
Sarmonsiill 2022-03-22 16:33:10 +00:00
parent 825599b8c8
commit 4ada419514
1 changed files with 8 additions and 9 deletions

View File

@ -24,8 +24,9 @@ pub fn run_parse() []Route {
routes := get_routes_from_config()
for route in routes {
if !route_exist(route) {
eprintln('route ${route.controller}/${route.function} not found')
ok, err := route_exist(route)
if !ok {
eprintln(err)
exit(1)
}
}
@ -33,25 +34,23 @@ pub fn run_parse() []Route {
return routes
}
fn route_exist(route Route) bool {
fn route_exist(route Route) (bool,string) {
file := 'Controllers/${route.controller}.v'
if !os.exists(file) {
eprintln('could not find $file')
return false
return false, 'could not find $file'
}
file_content := os.read_file(file) or {
eprintln('could not read $file')
return false
return false, 'could not read $file'
}
if !file_content.contains('fn ${route.function}()') {
return false
return false, '${route.function} not properly defined'
}
return true
return true, ''
}
fn get_routes_from_config() []Route {