1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

all: update repo to use the new error handling syntax (#8950)

This commit is contained in:
spaceface
2021-02-28 21:20:21 +01:00
committed by GitHub
parent b9a381f101
commit d63b7bc35a
135 changed files with 487 additions and 468 deletions

View File

@@ -1321,7 +1321,7 @@ import os
fn read_log() {
mut ok := false
mut f := os.open('log.txt') or { panic(err) }
mut f := os.open('log.txt') or { panic(err.msg) }
defer {
f.close()
}
@@ -2401,7 +2401,7 @@ any further.
The body of `f` is essentially a condensed version of:
```v ignore
resp := http.get(url) or { return error(err) }
resp := http.get(url) or { return err }
return resp.text
```
@@ -2418,7 +2418,7 @@ to break from the current block.
Note that `break` and `continue` can only be used inside a `for` loop.
V does not have a way to forcibly "unwrap" an optional (as other languages do,
for instance Rust's `unwrap()` or Swift's `!`). To do this, use `or { panic(err) }` instead.
for instance Rust's `unwrap()` or Swift's `!`). To do this, use `or { panic(err.msg) }` instead.
---
The third method is to provide a default value at the end of the `or` block.
@@ -3495,7 +3495,7 @@ Full list of builtin options:
module main
fn main() {
embedded_file := $embed_file('v.png')
mut fw := os.create('exported.png') or { panic(err) }
mut fw := os.create('exported.png') or { panic(err.msg) }
fw.write_bytes(embedded_file.data(), embedded_file.len)
fw.close()
}
@@ -3658,7 +3658,7 @@ eprintln('file: ' + @FILE + ' | line: ' + @LINE + ' | fn: ' + @MOD + '.' + @FN)
Another example, is if you want to embed the version/name from v.mod *inside* your executable:
```v ignore
import v.vmod
vm := vmod.decode( @VMOD_FILE ) or { panic(err) }
vm := vmod.decode( @VMOD_FILE ) or { panic(err.msg) }
eprintln('$vm.name $vm.version\n $vm.description')
```