Skip to content

HTMLRender interface: Instance method needs to return an error type #4210

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ljluestc
Copy link

@ljluestc ljluestc commented Apr 7, 2025

This PR updates the HTMLDebug struct in render/html.go to return nil from loadTemplate instead of panicking when no files or glob patterns are provided. This change makes the behavior more robust and eliminates the need for external files in some test cases.

Changes:

  • Modified render/html.go:
    • loadTemplate now returns nil instead of panicking when Files and Glob are empty.
    • Render handles a nil Template gracefully by returning nil.
  • Updated render/html_test.go:
    • TestHTMLDebugInstanceSuccess and TestHTMLDebugInstanceNoFilesOrGlob expect a nil Template when no files are provided, avoiding file dependencies.
  • Updated render/render_test.go:
    • Changed TestRenderHTMLDebugPanics to expect a nil Template instead of a panic, aligning with the new behavior.

Motivation:

  • Eliminates test failures due to missing testdata/template.html without requiring new files.
  • Improves robustness by avoiding unnecessary panics in debug mode.

Testing:

  • Verified locally with go test -v ./render/... in the gin repository.
  • All tests pass without external file dependencies.

@ljluestc ljluestc changed the title Update HTMLDebug to return nil instead of panicking and adjust tests HTMLRender interface: Instance method needs to return an error type Apr 7, 2025
Copy link

codecov bot commented Apr 11, 2025

Codecov Report

Attention: Patch coverage is 35.71429% with 9 lines in your changes missing coverage. Please review.

Project coverage is 98.73%. Comparing base (3dc1cd6) to head (a4006e2).
Report is 99 commits behind head on master.

Files with missing lines Patch % Lines
render/html.go 35.71% 6 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4210      +/-   ##
==========================================
- Coverage   99.21%   98.73%   -0.48%     
==========================================
  Files          42       44       +2     
  Lines        3182     3411     +229     
==========================================
+ Hits         3157     3368     +211     
- Misses         17       30      +13     
- Partials        8       13       +5     
Flag Coverage Δ
?
--ldflags="-checklinkname=0" -tags "sonic avx" 98.73% <35.71%> (?)
-tags go_json 98.73% <35.71%> (?)
-tags nomsgpack 98.72% <35.71%> (?)
go-1.18 ?
go-1.19 ?
go-1.20 ?
go-1.21 ?
go-1.23 98.73% <35.71%> (?)
go-1.24 98.73% <35.71%> (?)
macos-latest 98.73% <35.71%> (-0.48%) ⬇️
ubuntu-latest 98.73% <35.71%> (-0.48%) ⬇️

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.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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