Skip to content
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

fix: add error handling to workerPool #108

Closed
wants to merge 1 commit into from

Conversation

trym-b
Copy link
Contributor

@trym-b trym-b commented Mar 22, 2024

Motivation

The functions submitted to workerPool might
fail, and the errors they return should be
properly propagated.

Changes

To propagate the errors to the main goroutine, a
channel is used to transfer the errors. When
closing the workerPool any errors transferred
will be evaluated and if there is any none-nil
errors, the first one will be returned.

Quirks

This commit also disables the sub-linter gocyclo for a function in filewalker.go as it is the
refactoring triggered by this commit increase the
complexity.

This complexity is only intermediate and will be
removed upon further refactoring.

The original linter error was the following:

lint: internal/filewalker/filewalker.go#L192
cyclomatic complexity 31 of func `(*fileWalker).Walk`
is high (> 30) (gocyclo)

@trym-b trym-b marked this pull request as draft April 2, 2024 11:13
@trym-b
Copy link
Contributor Author

trym-b commented Apr 2, 2024

From IRL review with @maeb. If the error channel gets filled, then we will end up with a deadlock. So we need to ensure that we also empty the error channel before merging this PR. We should probably have a better test data set before continuing with this task

# Motivation

The functions submitted to `workerPool` might
fail, and the errors they return should be
properly propagated.

# Changes

To propagate the errors to the main goroutine, a
channel is used to transfer the errors. When
closing the `workerPool` any errors transferred
will be evaluated and if there is any none-nil
errors, the first one will be returned.

# Quirks

This commit also disables the sub-linter `gocyclo`
for a function in `filewalker.go` as it is the
refactoring triggered by this commit increase the
complexity.

This complexity is only intermediate and will be
removed upon further refactoring.

The original linter error was the following:
```
lint: internal/filewalker/filewalker.go#L192
cyclomatic complexity 31 of func `(*fileWalker).Walk`
is high (> 30) (gocyclo)
```
@trym-b trym-b force-pushed the fix/handle-file-walker-errors-part-2 branch from 9cc9ac2 to b185ee0 Compare April 2, 2024 12:04
@trym-b trym-b closed this May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants