Skip to content

Conversation

@Ja4V8s28Ck
Copy link
Contributor

@Ja4V8s28Ck Ja4V8s28Ck commented Oct 26, 2025

Description

  • Added structured logging via the error middleware and respective testcases has been refactored.
  • Fixed a bug where calling the delete endpoint with a non-existent user ID will not return USER_NOT_FOUND, rather it returns INTERNAL_SERVER_ERROR. ( I have added it as the last commit so that it can be cherry picked as a new PR, incase a need arise. )
  • One more thing I noted, with the recent fix where the viper properly overrides the .env file with the existing config.yaml, there is a testcase in
    func TestLoadConfig_ErrorPaths(t *testing.T) {
    t.Run("unmarshal error with invalid config structure", func(t *testing.T) {
    viper.Reset()
    tempDir := t.TempDir()
    invalidYAML := `
    app:
    name: 123
    environment: [this, should, not, be, an, array]
    database:
    port: "not_a_number"
    `
    path := createTempConfigFile(t, tempDir, "invalid.yaml", invalidYAML)
    _, err := LoadConfig(path)
    assert.Error(t, err)
    })
    which fails if there is a .env with a DATABASE_PORT value populated. So if uses with custom DATABASE_PORT in .env file will notice that, this test is failing.

Type of Change

  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • Unit tests
  • Integration tests
  • Manual testing
  • Postman/API testing

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@codecov
Copy link

codecov bot commented Oct 26, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@Ja4V8s28Ck Ja4V8s28Ck force-pushed the feat/add-structured-error-logging branch from 38e2935 to 640a2d5 Compare October 26, 2025 19:24
@vahiiiid
Copy link
Owner

vahiiiid commented Oct 26, 2025

Codecov Report

❌ Patch coverage is 21.29630% with 85 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/errors/errors.go 0.00% 71 Missing ⚠️
internal/errors/middleware.go 0.00% 9 Missing ⚠️
internal/user/handler.go 87.50% 2 Missing and 1 partial ⚠️
internal/user/service.go 0.00% 1 Missing and 1 partial ⚠️
📢 Thoughts on this report? Let us know!

@Ja4V8s28Ck
We need to write the test in case we don't decrease the codecov of the current status
So please try to write tests for those lines that are not covered at much as possible 🙂

Ja4V8s28Ck and others added 6 commits October 27, 2025 22:08
- Add comprehensive test suite for errors package (100% coverage)
  * Test all error constructors (NotFound, BadRequest, Conflict, etc.)
  * Test validation error conversion from Gin/validator
  * Test error middleware with various error types
  * Test integration scenarios with router

- Improve code documentation
  * Add godoc comments for all exported types and functions
  * Remove excessive obvious comments per project standards
  * Document error codes and their purposes
  * Add examples and edge case documentation

- Fix test expectations for structured error responses
  * Update handler tests to check 'message' field
  * Ensure consistent error response validation

- Update Swagger documentation
  * Regenerate docs with new error types

This enhances the structured error handling system with:
- Industry-standard test coverage (100%)
- Clear documentation following Go conventions
- Consistent error handling patterns
- Better developer experience with type-safe errors

Co-authored-by: Ja4V8s28Ck <Ja4V8s28Ck@users.noreply.github.com>
vahiiiid added a commit to vahiiiid/go-rest-api-docs that referenced this pull request Oct 27, 2025
- Add ERROR_HANDLING.md with complete guide to structured error system
  * Overview of error response structure
  * All error codes with descriptions and examples
  * Real-world curl examples for each error type
  * Client-side error handling in TypeScript, Python, and Go
  * Best practices and anti-patterns
  * Testing error responses
  * Integration with logging and monitoring

- Update mkdocs.yml navigation
  * Create new 'API Features' section
  * Move error handling, rate limiting, and logging together
  * Improve documentation organization

This documentation provides:
- Complete API error reference for developers
- Client integration examples in multiple languages
- Best practices for error handling patterns
- Testing strategies for error scenarios

Related to: vahiiiid/go-rest-api-boilerplate#84
@vahiiiid vahiiiid force-pushed the feat/add-structured-error-logging branch from 640a2d5 to 2079ef4 Compare October 27, 2025 21:26
- Mark universal-translator as direct dependency in go.mod (used in error tests)
- Add structured error handling to README features list
- Add Error Handling section to README with link to docs
- Add error handling link to documentation reference section

Co-authored-by: Ja4V8s28Ck <Ja4V8s28Ck@users.noreply.github.com>
@vahiiiid
Copy link
Owner

@Ja4V8s28Ck

I removed the commit with the 404 fixing of the delete user since it's fixed in the other PR
I rebased with the main
I added tests for the new error package with some small changes and updated the README

Please have a look
Thanks for the clean PR 🙏

@Ja4V8s28Ck
Copy link
Contributor Author

@Ja4V8s28Ck

I removed the commit with the 404 fixing of the delete user since it's fixed in the other PR I rebased with the main I added tests for the new error package with some small changes and updated the README

Please have a look Thanks for the clean PR 🙏

Thanks for polishing the PR into a better one. 🙏

@vahiiiid vahiiiid merged commit be9a604 into vahiiiid:main Oct 28, 2025
6 checks passed
vahiiiid added a commit to vahiiiid/go-rest-api-docs that referenced this pull request Oct 28, 2025
- Add ERROR_HANDLING.md with complete guide to structured error system
  * Overview of error response structure
  * All error codes with descriptions and examples
  * Real-world curl examples for each error type
  * Client-side error handling in TypeScript, Python, and Go
  * Best practices and anti-patterns
  * Testing error responses
  * Integration with logging and monitoring

- Update mkdocs.yml navigation
  * Create new 'API Features' section
  * Move error handling, rate limiting, and logging together
  * Improve documentation organization

This documentation provides:
- Complete API error reference for developers
- Client integration examples in multiple languages
- Best practices for error handling patterns
- Testing strategies for error scenarios

Related to: vahiiiid/go-rest-api-boilerplate#84
@Ja4V8s28Ck Ja4V8s28Ck deleted the feat/add-structured-error-logging branch October 28, 2025 19:36
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.

2 participants