diff --git a/vlib/x/vweb/static_handler.v b/vlib/x/vweb/static_handler.v index 38f44e5cb7643f..c03ff2fae26647 100644 --- a/vlib/x/vweb/static_handler.v +++ b/vlib/x/vweb/static_handler.v @@ -56,7 +56,7 @@ pub fn (mut sh StaticHandler) handle_static(directory_path string, root bool) !b // ``` pub fn (mut sh StaticHandler) host_handle_static(host string, directory_path string, root bool) !bool { if !os.exists(directory_path) { - return false + return error('directory `${directory_path}` does not exist. The directory should be relative to the current working directory: ${os.getwd()}') } dir_path := directory_path.trim_space().trim_right('/') mut mount_path := '' @@ -84,7 +84,7 @@ pub fn (mut sh StaticHandler) host_mount_static_folder_at(host string, directory if mount_path.len < 1 || mount_path[0] != `/` { return error('invalid mount path! The path should start with `/`') } else if !os.exists(directory_path) { - return error('directory "${directory_path}" does not exist') + return error('directory `${directory_path}` does not exist. The directory should be relative to the current working directory: ${os.getwd()}') } dir_path := directory_path.trim_right('/') diff --git a/vlib/x/vweb/tests/static_handler_test.v b/vlib/x/vweb/tests/static_handler_test.v index b99210652382d5..8ddc952601b789 100644 --- a/vlib/x/vweb/tests/static_handler_test.v +++ b/vlib/x/vweb/tests/static_handler_test.v @@ -49,6 +49,13 @@ fn run_app_test() { } app.static_mime_types['.what'] = vweb.mime_types['.txt'] + + if _ := app.handle_static('not_found', true) { + assert false, 'should throw directory not found error' + } else { + assert err.msg().starts_with('directory `not_found` does not exist') == true + } + app.handle_static('testdata', true) or { panic(err) } if _ := app.mount_static_folder_at('testdata', 'static') { @@ -60,7 +67,7 @@ fn run_app_test() { if _ := app.mount_static_folder_at('not_found', '/static') { assert true == false, 'should throw mount path does not exist error' } else { - assert err.msg() == 'directory "not_found" does not exist' + assert err.msg().starts_with('directory `not_found` does not exist') == true } app.mount_static_folder_at('testdata', '/static') or { panic(err) }