all: imp errors

This commit is contained in:
Stanislav Chzhen 2024-01-22 18:44:57 +03:00
parent e14456571c
commit d6732d13ad
4 changed files with 19 additions and 13 deletions

View File

@ -236,6 +236,7 @@
"updated_upstream_dns_toast": "Upstream servers successfully saved",
"dns_test_ok_toast": "Specified DNS servers are working correctly",
"dns_test_not_ok_toast": "Server \"{{key}}\": could not be used, please check that you've written it correctly",
"dns_test_not_ok_section_line_toast": "Section {{section}}: line {{line}}: could not be used, please check that you've written it correctly",
"dns_test_warning_toast": "Upstream \"{{key}}\" does not respond to test requests and may not work properly",
"unblock": "Unblock",
"block": "Block",

View File

@ -404,7 +404,14 @@ export const testUpstream = (
if (message.startsWith('WARNING:')) {
dispatch(addErrorToast({ error: i18next.t('dns_test_warning_toast', { key }) }));
} else if (message !== 'OK') {
dispatch(addErrorToast({ error: i18next.t('dns_test_not_ok_toast', { key }) }));
const info = message.substring(0, message.indexOf(':'));
const [sectionKey, line] = info.split(' ');
const section = i18next.t(sectionKey);
if (section && line) {
dispatch(addErrorToast({ error: i18next.t('dns_test_not_ok_section_line_toast', { section, line }) }));
} else {
dispatch(addErrorToast({ error: i18next.t('dns_test_not_ok_toast', { key }) }));
}
}
return message;
});

View File

@ -37,7 +37,7 @@ type upstreamResult struct {
// section of the upstream configuration.
section string
// isSpecific is true if the upstream is private.
// isPrivate is true if the upstream is private.
isPrivate bool
// isSpecific is true if the upstream is domain-specific.
@ -126,6 +126,7 @@ func (cv *upstreamConfigValidator) insertErrResults(
}
original := string(line)
cv.results[original] = fmt.Sprintf("%s %d: parsing error", section, idx+1)
}
}
@ -236,11 +237,8 @@ func (cv *upstreamConfigValidator) checkSrv(
return
}
serr := fmt.Errorf("%s: %w", res.section, res.err)
if res.isSpecific {
res.err = domainSpecificTestError{Err: serr}
} else {
res.err = serr
if res.err != nil && res.isSpecific {
res.err = domainSpecificTestError{Err: res.err}
}
}

View File

@ -55,7 +55,7 @@ func TestUpstreamConfigValidator(t *testing.T) {
name: "broken",
general: []string{badUps},
want: map[string]string{
badUps: generalSection + `: couldn't communicate with upstream: exchanging with ` +
badUps: `couldn't communicate with upstream: exchanging with ` +
badUps + ` over tcp: dns: id mismatch`,
},
}, {
@ -63,14 +63,14 @@ func TestUpstreamConfigValidator(t *testing.T) {
general: []string{goodUps, badUps, goodUps},
want: map[string]string{
goodUps: "OK",
badUps: generalSection + `: couldn't communicate with upstream: exchanging with ` +
badUps: `couldn't communicate with upstream: exchanging with ` +
badUps + ` over tcp: dns: id mismatch`,
},
}, {
name: "domain_specific_error",
general: []string{"[/domain.example/]" + badUps},
want: map[string]string{
badUps: `WARNING: ` + generalSection + `: couldn't communicate ` +
badUps: `WARNING: couldn't communicate ` +
`with upstream: exchanging with ` + badUps + ` over tcp: ` +
`dns: id mismatch`,
},
@ -84,7 +84,7 @@ func TestUpstreamConfigValidator(t *testing.T) {
name: "fallback_broken",
fallback: []string{badUps},
want: map[string]string{
badUps: fallbackSection + `: couldn't communicate with upstream: exchanging with ` +
badUps: `couldn't communicate with upstream: exchanging with ` +
badUps + ` over tcp: dns: id mismatch`,
},
}, {
@ -92,7 +92,7 @@ func TestUpstreamConfigValidator(t *testing.T) {
general: []string{"[/domain.example/]" + goodAndBadUps},
want: map[string]string{
goodUps: "OK",
badUps: `WARNING: ` + generalSection + `: couldn't communicate ` +
badUps: `WARNING: couldn't communicate ` +
`with upstream: exchanging with ` + badUps + ` over tcp: ` +
`dns: id mismatch`,
},
@ -109,7 +109,7 @@ func TestUpstreamConfigValidator(t *testing.T) {
private: []string{"[/domain.example/]" + goodAndBadUps},
want: map[string]string{
goodUps: "OK",
badUps: `WARNING: ` + generalSection + `: couldn't communicate ` +
badUps: `WARNING: couldn't communicate ` +
`with upstream: exchanging with ` + badUps + ` over tcp: ` +
`dns: id mismatch`,
},