Skip to content

fix: code quality improvements#2502

Open
dashitongzhi wants to merge 2 commits into
projectdiscovery:devfrom
dashitongzhi:fix/code-quality-improvements
Open

fix: code quality improvements#2502
dashitongzhi wants to merge 2 commits into
projectdiscovery:devfrom
dashitongzhi:fix/code-quality-improvements

Conversation

@dashitongzhi
Copy link
Copy Markdown
Contributor

@dashitongzhi dashitongzhi commented May 23, 2026

Code quality improvements for httpx.

Summary by CodeRabbit

Bug Fixes

  • Improved error handling for file pattern matching operations
  • Enhanced port parsing robustness to prevent invalid conversions
  • Fixed error handling in HTTP response decoding
  • Improved header value parsing reliability

Review Change Stack

dashitongzhi and others added 2 commits May 20, 2026 09:12
- Fix bug: return err instead of closeErr in DecodeData error path (httpx.go)
- Improve error handling for strconv.Atoi calls in multiple locations
- Change hammingDistanceThreshold from var to const since it's never modified
- Fix redundant return statement in ListFilesWithPattern
- Improve port parsing to handle empty port strings explicitly
Revert the defensive strconv.Atoi guard around the SkipDedupe branches:
values stored in r.hm are always integer strings written by this same
code path, so the parseErr/cnt>0 check is unreachable in practice, and
when taken literally it skipped the numHosts/numTargets increment for
duplicate inputs.
Copilot AI review requested due to automatic review settings May 23, 2026 01:16
@auto-assign auto-assign Bot requested a review from dwisiswant0 May 23, 2026 01:16
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 23, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 612f9504-df25-4677-8f66-29150759fa29

📥 Commits

Reviewing files that changed from the base of the PR and between 41e6d9b and 127074e.

📒 Files selected for processing (4)
  • common/fileutil/fileutil.go
  • common/hashes/jarm/jarmhash.go
  • common/httpx/httpx.go
  • runner/runner.go

Walkthrough

This PR improves error handling and parsing robustness across four modules. File glob operations now correctly return success without propagating errors. HTTP response handling validates decode errors and Content-Length header parsing explicitly. Port parsing in both JARM and runner now defensively checks for non-empty input and validates conversion success. Runner's hashing threshold becomes a compile-time constant.

Changes

Defensive error handling and parsing improvements

Layer / File(s) Summary
Core utility error handling
common/fileutil/fileutil.go, common/httpx/httpx.go
File glob matching returns nil error on successful matches instead of propagating in-scope errors; HTTP response handling now returns the correct decode error on failure and validates Content-Length header parsing before assignment instead of ignoring conversion errors.
Module-specific parsing and optimization
runner/runner.go, common/hashes/jarm/jarmhash.go
Runner's hammingDistanceThreshold is converted to a compile-time constant; both runner and JARM modules now defensively parse URL ports by checking for non-empty strings and validating strconv.Atoi success before use, defaulting to zero on parse failure.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • projectdiscovery/httpx#2499: Contains identical targeted fixes for error handling and parsing validation across fileutil, JARM, HTTPX, and runner modules.

Suggested reviewers

  • Mzack9999

Poem

🐰 A rabbit hops through error trails,
Where ports and globs no longer fail—
Each parse now checks before it lands,
Constants firm in steady hands.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'fix: code quality improvements' is overly vague and generic, using non-descriptive language that does not convey the specific changes made (error handling fixes, strconv.Atoi guards, port parsing improvements, etc.). Consider a more specific title like 'fix: improve error handling and port parsing' or 'fix: add defensive error handling in multiple modules' to better communicate the primary changes.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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.

3 participants