chore(all): review error wrappings
- remove repetitive `cannot` and `failed` prefixes - rename `unmarshaling` to `decoding`
This commit is contained in:
@@ -17,12 +17,12 @@ func (e *Extractor) Data(filepath string) (lines []string,
|
||||
connection models.Connection, err error) {
|
||||
lines, err = readCustomConfigLines(filepath)
|
||||
if err != nil {
|
||||
return nil, connection, fmt.Errorf("cannot read configuration file: %w", err)
|
||||
return nil, connection, fmt.Errorf("reading configuration file: %w", err)
|
||||
}
|
||||
|
||||
connection, err = extractDataFromLines(lines)
|
||||
if err != nil {
|
||||
return nil, connection, fmt.Errorf("cannot extract connection from file: %w", err)
|
||||
return nil, connection, fmt.Errorf("extracting connection from file: %w", err)
|
||||
}
|
||||
|
||||
return lines, connection, nil
|
||||
|
||||
@@ -54,14 +54,14 @@ func extractDataFromLine(line string) (
|
||||
case strings.HasPrefix(line, "proto "):
|
||||
protocol, err = extractProto(line)
|
||||
if err != nil {
|
||||
return nil, 0, "", fmt.Errorf("failed extracting protocol from proto line: %w", err)
|
||||
return nil, 0, "", fmt.Errorf("extracting protocol from proto line: %w", err)
|
||||
}
|
||||
return nil, 0, protocol, nil
|
||||
|
||||
case strings.HasPrefix(line, "remote "):
|
||||
ip, port, protocol, err = extractRemote(line)
|
||||
if err != nil {
|
||||
return nil, 0, "", fmt.Errorf("failed extracting from remote line: %w", err)
|
||||
return nil, 0, "", fmt.Errorf("extracting from remote line: %w", err)
|
||||
}
|
||||
return ip, port, protocol, nil
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ func Test_extractDataFromLines(t *testing.T) {
|
||||
},
|
||||
"extraction error": {
|
||||
lines: []string{"bla bla", "proto bad", "remote 1.2.3.4 1194 tcp"},
|
||||
err: errors.New("on line 2: failed extracting protocol from proto line: network protocol not supported: bad"),
|
||||
err: errors.New("on line 2: extracting protocol from proto line: network protocol not supported: bad"),
|
||||
},
|
||||
"only use first values found": {
|
||||
lines: []string{"proto udp", "proto tcp", "remote 1.2.3.4 443 tcp", "remote 5.2.3.4 1194 udp"},
|
||||
|
||||
Reference in New Issue
Block a user