mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
all: change optional to result of io (#16075)
This commit is contained in:
@@ -19,7 +19,7 @@ pub:
|
||||
// https://discord.com/channels/592103645835821068/592114487759470596/954101934988615721
|
||||
[deprecated: 'will be removed and not replaced due to flaky heuristics that leads to hard to find bugs']
|
||||
[deprecated_after: '2022-06-18']
|
||||
pub fn auto_config(toml string) ?Config {
|
||||
pub fn auto_config(toml string) !Config {
|
||||
mut config := Config{}
|
||||
if !toml.contains('\n') && os.is_file(toml) {
|
||||
config = Config{
|
||||
@@ -30,13 +30,13 @@ pub fn auto_config(toml string) ?Config {
|
||||
text: toml
|
||||
}
|
||||
}
|
||||
config.validate()?
|
||||
config.validate()!
|
||||
return config
|
||||
}
|
||||
|
||||
// validate returns an optional error if more than one of the fields
|
||||
// in `Config` has a non-default value (empty string).
|
||||
fn (c Config) validate() ? {
|
||||
fn (c Config) validate() ! {
|
||||
if c.file_path != '' && c.text != '' {
|
||||
error(@MOD + '.' + @FN +
|
||||
' ${typeof(c).name} should contain only one of the fields `file_path` OR `text` filled out')
|
||||
@@ -48,8 +48,8 @@ fn (c Config) validate() ? {
|
||||
|
||||
// read_input returns either Config.text or the read file contents of Config.file_path
|
||||
// depending on which one is not empty.
|
||||
pub fn (c Config) read_input() ?string {
|
||||
c.validate()?
|
||||
pub fn (c Config) read_input() !string {
|
||||
c.validate()!
|
||||
mut text := c.text
|
||||
if text == '' && os.is_file(c.file_path) {
|
||||
text = os.read_file(c.file_path) or {
|
||||
|
||||
Reference in New Issue
Block a user