Skip to content

feat(code): log unavail engines as an err while validating#6326

Merged
ehsandeep merged 2 commits intodevfrom
dwisiswant0/feat/code/log-unavail-engines-as-an-err-while-validating
Jul 18, 2025
Merged

feat(code): log unavail engines as an err while validating#6326
ehsandeep merged 2 commits intodevfrom
dwisiswant0/feat/code/log-unavail-engines-as-an-err-while-validating

Conversation

@dwisiswant0
Copy link
Member

@dwisiswant0 dwisiswant0 commented Jul 16, 2025

Proposed changes

Closes #6303

Also leave some notes.

Proof

# missing-engine.yaml
id: missing-engine

info:
  name: Missing engine
  author: dwisiswant0
  severity: info
  description: Missing engines should not fatal
  tags: foo

code:
  - engine:
      - foo
    source: foo bar

    matchers:
      - type: status
        status:
          - 204
        condition: and
$ make build
$ ./bin/nuclei -t /tmp/missing-engine.yaml -code -validate

                     __     _
   ____  __  _______/ /__  (_)
  / __ \/ / / / ___/ / _ \/ /
 / / / / /_/ / /__/ /  __/ /
/_/ /_/\__,_/\___/_/\___/_/   v3.4.7

		projectdiscovery.io

[VER] Started metrics server at localhost:9092
[ERR] [missing-engine] engines 'foo' not available on host <- no valid engine found
[INF] All templates validated successfully

Checklist

  • Pull request is created against the dev branch
  • All checks passed (lint, unit/integration/regression tests etc.) with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling during template validation to allow validation to proceed even if certain engines are not installed, enhancing flexibility for users running in validation mode.

Signed-off-by: Dwi Siswanto <git@dw1.io>
@dwisiswant0 dwisiswant0 requested a review from Mzack9999 July 16, 2025 07:16
@auto-assign auto-assign bot requested a review from dogancanbakir July 16, 2025 07:16
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 16, 2025

Walkthrough

The change updates the error handling in the Request.Compile method for missing engines. During template validation (Validate flag set), missing engines now log an error instead of returning it, allowing validation to continue. For normal operation, the error is still returned as before. No other logic or interface changes are introduced.

Changes

File(s) Change Summary
pkg/protocols/code/code.go Modified error handling in Request.Compile to log (not return) engine errors during validation; added explanatory comments.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Request
    participant EngineFactory

    User->>Request: Compile(options)
    Request->>EngineFactory: NewGoZeroEngine()
    alt Engine creation fails
        alt options.Validate is true
            Request->>Request: Log error, continue
        else options.Validate is false
            Request->>User: Return error
        end
    else Engine creation succeeds
        Request->>Request: Assign engine
    end
    Request-->>User: Return (success or continue)
Loading

Assessment against linked issues

Objective Addressed Explanation
Missing engine in templates validation should trigger a WARNING not a FATAL error (#6303)

Poem

A bunny hopped through code today,
Tweaked errors that got in the way.
Now missing engines just warn,
No more fatal stops at dawn!
With validation running free,
Bugs are gone—so hoppily! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 000ae45 and a686141.

📒 Files selected for processing (1)
  • pkg/protocols/code/code.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/protocols/code/code.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Tests (ubuntu-latest)
  • GitHub Check: Tests (macOS-latest)
  • GitHub Check: Tests (windows-latest)
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
pkg/protocols/code/code.go (1)

99-113: Consider condensing the TODO comment for better maintainability.

While the detailed explanation is valuable, the comment is quite lengthy and includes external URLs that may become stale over time. Consider:

  1. Moving the detailed technical discussion to documentation or an issue
  2. Keeping a more concise comment in the code
  3. Using issue references instead of direct URLs
-		// NOTE(dwisiswant0): In validation mode, skip engine avail check to
-		// allow template validation w/o requiring all engines to be installed
-		// on the host.
-		//
-		// TODO: Ideally, error checking should be done at the lowest level. For
-		// example, we can reuse errors[1][2] from the `projectdiscovery/gozero`
-		// package and wrap (yes, not string format[3][4]) em inside
-		// `projectdiscovery/utils/errors` package to preserve error semantics
-		// and enable runtime type assertion via builtin `errors.Is` function
-		// for granular err handling in the callstack.
-		//
-		// [1]: https://github.com/projectdiscovery/gozero/blob/v0.0.3/gozero.go#L20
-		// [2]: https://github.com/projectdiscovery/gozero/blob/v0.0.3/gozero.go#L35
-		// [3]: https://github.com/projectdiscovery/utils/blob/v0.4.21/errors/enriched.go#L85
-		// [4]: https://github.com/projectdiscovery/utils/blob/v0.4.21/errors/enriched.go#L137
+		// NOTE(dwisiswant0): In validation mode, skip engine availability check to
+		// allow template validation without requiring all engines to be installed.
+		// TODO: Improve error handling semantics by wrapping errors from gozero
+		// package to enable runtime type assertion via errors.Is function.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3e9bee7 and 000ae45.

📒 Files selected for processing (1)
  • pkg/protocols/code/code.go (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
pkg/protocols/code/code.go (1)
pkg/types/types.go (1)
  • Options (32-464)
🔇 Additional comments (2)
pkg/protocols/code/code.go (2)

97-97: Error message formatting is clear and informative.

The error message provides good context including template ID and the specific engines that are unavailable.


114-118: Conditional error handling logic is correct and aligns with PR objectives.

The implementation properly distinguishes between validation mode (log error, continue) and normal mode (return error). This allows template validation to proceed even when engines are unavailable, which matches the PR requirements.

Signed-off-by: Dwi Siswanto <git@dw1.io>
@ehsandeep ehsandeep merged commit 9133e0d into dev Jul 18, 2025
30 of 31 checks passed
@ehsandeep ehsandeep deleted the dwisiswant0/feat/code/log-unavail-engines-as-an-err-while-validating branch July 18, 2025 18:42
Ice3man543 pushed a commit that referenced this pull request Aug 2, 2025
* feat(code): log unavail engines as an err while validating

Signed-off-by: Dwi Siswanto <git@dw1.io>

* chore(chore): i meant highest level

Signed-off-by: Dwi Siswanto <git@dw1.io>

---------

Signed-off-by: Dwi Siswanto <git@dw1.io>
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.

[BUG] Missing engine in templates validation should trigger a WARNING not a FATAL error

3 participants