Skip to content

Conversation

cnlangzi
Copy link
Member

@cnlangzi cnlangzi commented Feb 9, 2025

Changed

Fixed

  • fixe panic when no any view is avaiable.

Added

Tests

Tasks to complete before merging PR:

  • Ensure unit tests are passing. If not run make unit-test to check for any regressions 📋
  • Ensure lint tests are passing. if not run make lint to check for any issues
  • Ensure codecov/patch is passing for changes.

Summary by Sourcery

Bug Fixes:

  • Fixed a panic that occurred when no view was available.

Copy link

sourcery-ai bot commented Feb 9, 2025

Reviewer's Guide by Sourcery

This pull request fixes an issue where the absence of a view would cause the application to panic. Instead of triggering a panic, the code now properly handles the situation by checking for the ErrViewNotFound error and responding with a 404 status. The changes are implemented by adding error checks in both the application handler and the context, as well as defining a new error indicator for missing views.

Sequence diagram for ErrViewNotFound error handling

sequenceDiagram
    participant Client
    participant App
    participant Context

    Client->>App: Request view
    App->>Context: Call View(data, options)
    Context-->>App: Return ErrViewNotFound (if no view available)
    App->>Client: Write 404 status with "View Not Found" response
Loading

Class diagram for Error Handling Enhancement

classDiagram
    class App {
      +HandleFile(name, v)
    }

    class Context {
      +View(data, options)
      -Routing: Routing
    }

    class Routing {
      +Viewers: []
    }

    class ErrViewNotFound

    Context --> Routing : uses
    Context ..> ErrViewNotFound : returns
    App ..> ErrViewNotFound : checks for error
Loading

File-Level Changes

Change Details Files
Handle missing view error in file handling.
  • Added error check in the file handling function to detect ErrViewNotFound.
  • Modified the response logic to write a 404 status and a 'View Not Found' message instead of triggering a panic.
app.go
Return a specific error when no view is available.
  • Updated the context view function to return ErrViewNotFound if there are no viewers available.
  • Ensured that the fallback logic is only used when there is at least one viewer.
context.go
Define a new error for missing views.
  • Introduced the ErrViewNotFound error in the errors module for better error identification and handling.
errs.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @cnlangzi - I've reviewed your changes - here's some feedback:

Overall Comments:

  • When writing the 404 response, set the appropriate Content-Type header (e.g. text/plain) to clearly communicate the response type.
  • Consider handling the error from ctx.Response.Write rather than suppressing it with nolint to avoid silent failures.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link

codecov bot commented Feb 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.93%. Comparing base (470a0dc) to head (fadd799).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #37      +/-   ##
==========================================
+ Coverage   91.89%   91.93%   +0.04%     
==========================================
  Files          38       38              
  Lines        1407     1414       +7     
==========================================
+ Hits         1293     1300       +7     
  Misses         78       78              
  Partials       36       36              
Flag Coverage Δ
Unit-Tests 91.93% <100.00%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

deepsource-io bot commented Feb 9, 2025

Here's the code health analysis summary for commits 470a0dc..fadd799. View details on DeepSource ↗.

Analysis Summary

AnalyzerStatusSummaryLink
DeepSource Go LogoGo✅ SuccessView Check ↗

💡 If you’re a repository administrator, you can configure the quality gates from the settings.

@cnlangzi cnlangzi merged commit f4c86b5 into main Feb 9, 2025
7 checks passed
@cnlangzi cnlangzi deleted the fix/view_not_found branch February 9, 2025 02:05
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.

1 participant