mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
all: bring back panic(err.msg)
-> panic(err)
(#9022)
This commit is contained in:
@@ -96,10 +96,10 @@ fn (am AssetManager) combine(asset_type string, to_file bool) string {
|
||||
return out
|
||||
}
|
||||
if !os.is_dir(am.cache_dir) {
|
||||
os.mkdir(am.cache_dir) or { panic(err.msg) }
|
||||
os.mkdir(am.cache_dir) or { panic(err) }
|
||||
}
|
||||
mut file := os.create(out_file) or { panic(err.msg) }
|
||||
file.write(out.bytes()) or { panic(err.msg) }
|
||||
mut file := os.create(out_file) or { panic(err) }
|
||||
file.write(out.bytes()) or { panic(err) }
|
||||
file.close()
|
||||
return out_file
|
||||
}
|
||||
|
@@ -6,7 +6,7 @@ import os
|
||||
// unique cache dirs are needed per test function.
|
||||
fn clean_cache_dir(dir string) {
|
||||
if os.is_dir(dir) {
|
||||
os.rmdir_all(dir) or { panic(err.msg) }
|
||||
os.rmdir_all(dir) or { panic(err) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,10 +21,10 @@ fn cache_dir(test_name string) string {
|
||||
fn get_test_file_path(file string) string {
|
||||
path := os.join_path(base_cache_dir(), file)
|
||||
if !os.is_dir(base_cache_dir()) {
|
||||
os.mkdir_all(base_cache_dir()) or { panic(err.msg) }
|
||||
os.mkdir_all(base_cache_dir()) or { panic(err) }
|
||||
}
|
||||
if !os.exists(path) {
|
||||
os.write_file(path, get_test_file_contents(file)) or { panic(err.msg) }
|
||||
os.write_file(path, get_test_file_contents(file)) or { panic(err) }
|
||||
}
|
||||
return path
|
||||
}
|
||||
|
@@ -102,14 +102,14 @@ fn assert_common_http_headers(x http.Response) {
|
||||
}
|
||||
|
||||
fn test_http_client_index() {
|
||||
x := http.get('http://127.0.0.1:$sport/') or { panic(err.msg) }
|
||||
x := http.get('http://127.0.0.1:$sport/') or { panic(err) }
|
||||
assert_common_http_headers(x)
|
||||
assert x.headers['Content-Type'] == 'text/plain'
|
||||
assert x.text == 'Welcome to VWeb'
|
||||
}
|
||||
|
||||
fn test_http_client_chunk_transfer() {
|
||||
x := http.get('http://127.0.0.1:$sport/chunk') or { panic(err.msg) }
|
||||
x := http.get('http://127.0.0.1:$sport/chunk') or { panic(err) }
|
||||
assert_common_http_headers(x)
|
||||
assert x.headers['Transfer-Encoding'] == 'chunked'
|
||||
assert x.text == 'Lorem ipsum dolor sit amet, consetetur sadipscing'
|
||||
@@ -122,45 +122,45 @@ fn test_http_client_404() {
|
||||
'http://127.0.0.1:$sport/unknown',
|
||||
]
|
||||
for url in url_404_list {
|
||||
res := http.get(url) or { panic(err.msg) }
|
||||
res := http.get(url) or { panic(err) }
|
||||
assert res.status_code == 404
|
||||
}
|
||||
}
|
||||
|
||||
fn test_http_client_simple() {
|
||||
x := http.get('http://127.0.0.1:$sport/simple') or { panic(err.msg) }
|
||||
x := http.get('http://127.0.0.1:$sport/simple') or { panic(err) }
|
||||
assert_common_http_headers(x)
|
||||
assert x.headers['Content-Type'] == 'text/plain'
|
||||
assert x.text == 'A simple result'
|
||||
}
|
||||
|
||||
fn test_http_client_html_page() {
|
||||
x := http.get('http://127.0.0.1:$sport/html_page') or { panic(err.msg) }
|
||||
x := http.get('http://127.0.0.1:$sport/html_page') or { panic(err) }
|
||||
assert_common_http_headers(x)
|
||||
assert x.headers['Content-Type'] == 'text/html'
|
||||
assert x.text == '<h1>ok</h1>'
|
||||
}
|
||||
|
||||
fn test_http_client_settings_page() {
|
||||
x := http.get('http://127.0.0.1:$sport/bilbo/settings') or { panic(err.msg) }
|
||||
x := http.get('http://127.0.0.1:$sport/bilbo/settings') or { panic(err) }
|
||||
assert_common_http_headers(x)
|
||||
assert x.text == 'username: bilbo'
|
||||
//
|
||||
y := http.get('http://127.0.0.1:$sport/kent/settings') or { panic(err.msg) }
|
||||
y := http.get('http://127.0.0.1:$sport/kent/settings') or { panic(err) }
|
||||
assert_common_http_headers(y)
|
||||
assert y.text == 'username: kent'
|
||||
}
|
||||
|
||||
fn test_http_client_user_repo_settings_page() {
|
||||
x := http.get('http://127.0.0.1:$sport/bilbo/gostamp/settings') or { panic(err.msg) }
|
||||
x := http.get('http://127.0.0.1:$sport/bilbo/gostamp/settings') or { panic(err) }
|
||||
assert_common_http_headers(x)
|
||||
assert x.text == 'username: bilbo | repository: gostamp'
|
||||
//
|
||||
y := http.get('http://127.0.0.1:$sport/kent/golang/settings') or { panic(err.msg) }
|
||||
y := http.get('http://127.0.0.1:$sport/kent/golang/settings') or { panic(err) }
|
||||
assert_common_http_headers(y)
|
||||
assert y.text == 'username: kent | repository: golang'
|
||||
//
|
||||
z := http.get('http://127.0.0.1:$sport/missing/golang/settings') or { panic(err.msg) }
|
||||
z := http.get('http://127.0.0.1:$sport/missing/golang/settings') or { panic(err) }
|
||||
assert z.status_code == 404
|
||||
}
|
||||
|
||||
@@ -175,9 +175,7 @@ fn test_http_client_json_post() {
|
||||
age: 123
|
||||
}
|
||||
json_for_ouser := json.encode(ouser)
|
||||
mut x := http.post_json('http://127.0.0.1:$sport/json_echo', json_for_ouser) or {
|
||||
panic(err.msg)
|
||||
}
|
||||
mut x := http.post_json('http://127.0.0.1:$sport/json_echo', json_for_ouser) or { panic(err) }
|
||||
$if debug_net_socket_client ? {
|
||||
eprintln('/json_echo endpoint response: $x')
|
||||
}
|
||||
@@ -186,7 +184,7 @@ fn test_http_client_json_post() {
|
||||
nuser := json.decode(User, x.text) or { User{} }
|
||||
assert '$ouser' == '$nuser'
|
||||
//
|
||||
x = http.post_json('http://127.0.0.1:$sport/json', json_for_ouser) or { panic(err.msg) }
|
||||
x = http.post_json('http://127.0.0.1:$sport/json', json_for_ouser) or { panic(err) }
|
||||
$if debug_net_socket_client ? {
|
||||
eprintln('/json endpoint response: $x')
|
||||
}
|
||||
|
@@ -594,7 +594,7 @@ pub fn (mut ctx Context) parse_multipart_form(s string, b string) {
|
||||
}
|
||||
|
||||
fn (mut ctx Context) scan_static_directory(directory_path string, mount_path string) {
|
||||
files := os.ls(directory_path) or { panic(err.msg) }
|
||||
files := os.ls(directory_path) or { panic(err) }
|
||||
if files.len > 0 {
|
||||
for file in files {
|
||||
full_path := directory_path + '/' + file
|
||||
@@ -613,7 +613,7 @@ fn (mut ctx Context) scan_static_directory(directory_path string, mount_path str
|
||||
}
|
||||
|
||||
// Handles a directory static
|
||||
// If `root` is set the mount path for the dir will be in '/'
|
||||
// If `root` is set the mount path for the dir will be in '/'
|
||||
pub fn (mut ctx Context) handle_static(directory_path string, root bool) bool {
|
||||
if ctx.done || !os.exists(directory_path) {
|
||||
return false
|
||||
@@ -629,7 +629,7 @@ pub fn (mut ctx Context) handle_static(directory_path string, root bool) bool {
|
||||
}
|
||||
|
||||
// Serves a file static
|
||||
// `url` is the access path on the site, `file_path` is the real path to the file, `mime_type` is the file type
|
||||
// `url` is the access path on the site, `file_path` is the real path to the file, `mime_type` is the file type
|
||||
pub fn (mut ctx Context) serve_static(url string, file_path string, mime_type string) {
|
||||
ctx.static_files[url] = file_path
|
||||
ctx.static_mime_types[url] = mime_type
|
||||
|
Reference in New Issue
Block a user