Skip to content

all: Adopt recommended linters in CI and address the problems pointed by them#142

Merged
marcelosalloum merged 27 commits intomainfrom
marcelo/polish-project-config-and-CI
Apr 18, 2025
Merged

all: Adopt recommended linters in CI and address the problems pointed by them#142
marcelosalloum merged 27 commits intomainfrom
marcelo/polish-project-config-and-CI

Conversation

@marcelosalloum
Copy link
Copy Markdown
Collaborator

@marcelosalloum marcelosalloum commented Apr 16, 2025

What

Adopt recommended linters in CI and address the problems pointed by them

Fixes include:

  • GET /tss/transactions/{hash} would return an invalid JSON when the resource was not found
  • Many errors where not being wrapped with fmt.Errorf("{message}: %w"), which made issues hard to debug.
  • Some occurrences of the wrong error being returned in a funcrtion/method
  • Dozens of occurrences of shadowing variables, some of them in the actual code but most of them in the tests.
  • Many tests were asserting the wrong object for an error.
  • Sentry tests were failing but ut wasn't being captured since the errors were being ignored.
  • Error assertions were fixed to use errors.As and errors.Is, so wrapped errors can also be captured.
  • Update naming from some error types (should end with ...Error) and error variables (should start with Err...) to be go idiomatic.

Additionally:

  • Moved all mocks to a file in their package called mocks.go, for consistency.
  • Reorganize imports using goimports

Why

It's good practice to use linters, specially the ones that capture errors and help making the code more debuggable and idiomatic.

Checklist

PR Structure

  • It is not possible to break this PR down into smaller PRs.
  • This PR does not mix refactoring changes with feature changes.
  • This PR's title starts with name of package that is most changed in the PR, or all if the changes are broad or impact many packages.

Thoroughness

  • This PR adds tests for the new functionality or fixes.
  • All updated queries have been tested (refer to this check if the data set returned by the updated query is expected to be same as the original one).

Release

  • This is not a breaking change.
  • This is ready to be tested in development.
  • The new functionality is gated with a feature flag if this is not ready for production.

…se transaction, and there would be no value in doing so. Kinda bogus code.
…ls functions are meant to be used from within tests by requiring a test object and handling the internal error inside of it.
…ts. This exposed some issues that will be handled in the next commit.
@marcelosalloum marcelosalloum requested a review from Copilot April 16, 2025 01:03
@marcelosalloum marcelosalloum self-assigned this Apr 16, 2025
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates the CI configuration to run linters correctly and fixes several issues flagged by the linters such as error wrapping, incorrect error messages, variable shadowing, and test assertions. Key changes include:

  • Improving error handling (using fmt.Errorf with %w) and consistent error messages.
  • Refactoring test files to use testify/require and reorganizing imports.
  • Updating CI workflows and linter configurations to enforce code standards.

Reviewed Changes

Copilot reviewed 101 out of 101 changed files in this pull request and generated no comments.

Show a summary per file
File Description
internal/data/payments_test.go Removed duplicate import lines and reordered imports for clarity
internal/data/payments.go Improved error checking by using errors.Is for sql.ErrNoRows
internal/data/fixtures.go Reordered import statements with minor cleanup
internal/data/accounts_test.go Cleaned up blank lines in test setup
internal/apptracker/sentry/sentry_tracker*.go Updated error wrapping and test setups for Sentry tracker functionality
internal/apptracker/sentry/mocks.go Added helper for mock setup with t.Cleanup for restoration of function pointers
cmd/utils/* Updated error messages and error wrapping in signature client handling
cmd/utils/password_prompter.go Added error wrapping for IO related calls
cmd/migrate.go, cmd/ingest.go, cmd/distribution_account.go Minor error wrapping and formatting improvements
.golangci.yml & .github/workflows/go.yaml Updated linter configurations and CI workflows with improved caching
Comments suppressed due to low confidence (1)

internal/apptracker/sentry/sentry_tracker.go:37

  • Ensure that deferring FlushFunc (and similarly, RecoverFunc on the next line) is appropriate even when the Sentry initialization fails. Consider calling these functions only upon successful initialization to prevent unintended side effects.
defer FlushFunc(time.Second * time.Duration(flushFreq))

func (t *transactionService) BuildAndSignTransactionWithChannelAccount(ctx context.Context, operations []txnbuild.Operation, timeoutInSecs int64) (*txnbuild.Transaction, error) {
var tx *txnbuild.Transaction
var channelAccountPublicKey string
err := db.RunInTransaction(ctx, t.DB, nil, func(dbTx db.Transaction) error {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the call to RunInTransaction here because it was not being used. The dbTx was not being applied anywhere and considering there's only one database query, at the very last step here, then the database transaction serves no purpose here.

if errors.Is(err, store.ErrPublicKeyAlreadyExists) {
return err
}
return fmt.Errorf("storing distribution account encrypted private key: %w", err)
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this assertion because the function returns the same error anyway, and it can be parsed downstream using errors.Is

@marcelosalloum marcelosalloum changed the title all: update CI to run the linters correctly and fixed the issues pointed by it all: adopt recommended linters in CI and address the problems pointed by them Apr 16, 2025
@marcelosalloum marcelosalloum changed the title all: adopt recommended linters in CI and address the problems pointed by them all: Adopt recommended linters in CI and address the problems pointed by them Apr 16, 2025
@marcelosalloum marcelosalloum marked this pull request as ready for review April 16, 2025 01:26
@marcelosalloum marcelosalloum added enhancement New feature or request github_actions Pull requests that update GitHub Actions code labels Apr 16, 2025
@marcelosalloum marcelosalloum force-pushed the marcelo/polish-project-config-and-CI branch from 8fa8c7f to 38f1464 Compare April 16, 2025 18:52
@marcelosalloum marcelosalloum merged commit 6dce817 into main Apr 18, 2025
5 checks passed
@marcelosalloum marcelosalloum deleted the marcelo/polish-project-config-and-CI branch April 18, 2025 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request github_actions Pull requests that update GitHub Actions code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants