-
-
Notifications
You must be signed in to change notification settings - Fork 214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
application startup should fail if initial download of a single list failed (#310) #313
Conversation
Sorry I'm fairly new to unit tests, will try fixing the problem. |
…ors as temporary" This reverts commit b41ccc3.
Hi, thank you for your work! |
Hi, I added the functions as stub for further error handling. I tried to introduce a generic solution for error handling during server startup but I'm still kind of new to the conzept of working without methode overrides and abstract classes so there will be a better solution for sure(got stuck at the Chain function). 😅 |
Its a good idea to prepare the code to handle errors in all resolvers. I think the errors could be handled just before the chain func. following must be replaced
by invoking each "New*" function and collecting errors. In error case -> log errors and fail to start, if no error occurred -> call chain function. |
for group, links := range b.groupToLinks { | ||
cacheForGroup := b.createCacheForGroup(links) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic based on "elementCount" doesn't work if a group has multiple links and some of them are successful, for Example this config:
port: 55555
logLevel: info
blocking:
blackLists:
xyz:
- /wrongpath/whitelist.txt
ads:
- http://wrongdomain/hosts.txt
- https://s3.amazonaws.com/lists.disconnect.me/simple_tracking.txt
upstream:
default:
- https://8.8.8.8/dns-query
- https://8.8.4.4/dns-query
I would expect 2 errors, but I get only one, because the "ads" group has more than 0 elements
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested this scenario with commit b41ccc3 but as the unit test(list_cache_test.go:133) indicated that this was the expected behavior. The commit was reverted afterwards in commit 98ddbb2.
I missed to test the following solution throughout. 😞
I would propose to let createCacheForGroup additionally return errors, which could be handeld afterwards.
@@ -205,22 219,27 @@ func (b *ListCache) downloadFile(link string) (io.ReadCloser, error) { | |||
if resp, err = client.Get(link); err == nil { | |||
if resp.StatusCode == http.StatusOK { | |||
return resp.Body, nil | |||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Hey, |
Hi, already seen it and answered 😉 |
Let me know if you need help or if I can take a task or a part |
I tested this solution with your config which results in two errors and 'make test' got through without errors. |
attempt | ||
} else { | ||
return nil, err | ||
} else if errors.As(err, &dnsErr) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Different message for DNS resolution errors 👍
@@ -47,7 47,7 @@ func getServerAddress(addr string) string { | |||
} | |||
|
|||
// NewServer creates new server instance with passed config | |||
func NewServer(cfg *config.Config) (server *Server, err error) { | |||
func NewServer(cfg *config.Config) (server *Server, errors []error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussion: typically in Go, if a function can't handle error internally, it returns an error as the last parameter. It is possible to combine multiple errors into one with wrapping (see error wrapping). Here is some example: https://play.golang.org/p/Kwbek7RV1Lw
I think it would be more "go-ish" to return here just "error" and not a slice of errors. If multiple errors can ocurre, they should be wrapped. This would make the code simpler and convenient.
What do you think?
We can also merge it with error slice, I'm currently not sure what is the better solution
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't know about the wrapping and seen error more than some kind of object than an actual exception 😅
Wrapping them seems logical.
Codecov Report
@@ Coverage Diff @@
## development #313 /- ##
===============================================
- Coverage 95.27% 94.64% -0.64%
===============================================
Files 29 29
Lines 2160 2202 42
===============================================
Hits 2058 2084 26
- Misses 74 83 9
- Partials 28 35 7
Continue to review full report at Codecov.
|
Changes: