Skip to content

fix(loader): fail -validate when a template path can't be found - #7959

Merged
Mzack9999 merged 1 commit into
projectdiscovery:devfrom
arxhr007:fix/7949-validate-missing-path
Oct 27, 2026
Merged

Mzack9999 merged 1 commit into
projectdiscovery:devfrom
arxhr007:fix/7949-validate-missing-path

Conversation

@arxhr007

@arxhr007 arxhr007 commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Proposed changes

Fixes #7949

nuclei -validate -t <path> logs Could not find template for a path that doesn't exist, then still prints All templates validated successfully and exits 0. A mistyped path in a CI step passes.

Store.ValidateTemplates ignored the paths that GetTemplatesPath couldn't resolve. logErroredTemplates now returns how many of them were not handled by NotFoundCallback, and ValidateTemplates returns its validation error when that count is not zero. Templates and workflows that do resolve are still validated, so their errors are reported too. A path the callback resolves is still accepted.

Proof

Built the binary from dev and from this branch, same command:

$ nuclei -duc -nc -validate -t /tmp/no-such-templates/

Before:

[ERR] Could not find template '/tmp/no-such-templates/': could not find file: open /tmp/no-such-templates/: no such file or directory
[INF] All templates validated successfully
exit=0

After:

[ERR] Could not find template '/tmp/no-such-templates/': could not find file: open /tmp/no-such-templates/: no such file or directory
[FTL] Could not validate templates: errors occurred during template validation
exit=1

Also checked with this branch:

  • one valid template: All templates validated successfully, exit 0
  • one valid template plus a missing path (-t ok.yaml -t /tmp/nope.yaml): error, exit 1

New tests in pkg/catalog/loader/loader_test.go:

  • TestValidateTemplatesRejectsMissingTemplatePath fails on dev ("An error is expected but got nil") and passes here.
  • TestValidateTemplatesAcceptsMissingPathHandledByCallback covers the callback case.
  • The store setup of the existing validate test moved into a small helper, newValidateStore, so the three tests share it.

What I ran (Linux, Go 1.27.3): go vet and go test -count=1 on ./pkg/catalog/... and ./internal/runner/..., all passing. I did not run the full make test or the integration suite.

I used an AI assistant while working on this.

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
    • Catalog validation now reports an error and fails when template or workflow paths cannot be resolved, unless the configured missing-path handler handles them. Validation succeeds only when its checks pass and no unhandled paths remain. This makes missing catalog resources visible during validation rather than allowing validation to succeed despite unresolved paths.

`nuclei -validate -t /no/such/path` logged "Could not find template" and
then still printed "All templates validated successfully" and exited 0,
so a mistyped path in a CI step passed. ValidateTemplates ignored the
paths that GetTemplatesPath could not resolve.

Count the paths that aren't handled by NotFoundCallback and return the
validation error when there is any. Paths the callback resolves are
still accepted.

Fixes #7949
@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8fc875d8-329a-4fcc-97dc-ab9c2a122959
Commits

Reviewing files that changed from the base of the PR and between abcdcf1 and a4afaa4.

Files selected for processing: 2
  • pkg/catalog/loader/loader.go
  • pkg/catalog/loader/loader_test.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Walkthrough

Validation now fails when template or workflow paths are unresolved and are not handled by NotFoundCallback. Tests cover both unhandled and callback-handled missing paths.

Changes

Template validation

Layer / File(s) Summary
Count unresolved paths and set validation result
pkg/catalog/loader/loader.go
logErroredTemplates returns the number of paths not handled by NotFoundCallback. ValidateTemplates includes that count when determining success.
Test missing-path outcomes
pkg/catalog/loader/loader_test.go
Tests verify that an unhandled missing path causes validation to fail and that a callback-handled path does not. Shared validation-test setup is extracted into newValidateStore.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related issues

  • projectdiscovery/nuclei#7949 — The changes make validation fail when a template path cannot be resolved and is not handled by the callback.

Suggested reviewers: dwisiswant0

Merge Risk: Minimal · up to a4afa

Missing paths fail validation; no merge-blocking issue was identified.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within survi… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "fix(loader): fail -validate when a template path can't be found" matches the main change. The raw summary and PR objectives both show that ValidateTemplates now returns an error when GetTem…
Linked Issues check Passed Issue #7949 requires a non-zero validation result when a -t path resolves to no template and no success report. ValidateTemplates now counts unresolved paths that NotFoundCallback does not handl…
Out of Scope Changes check Passed The changes stay within issue #7949. The production change updates missing-path handling in ValidateTemplates. The test helper extraction and the two new tests support this behavior. Workflow handli…
Full details: Title check

Explanation

The title "fix(loader): fail -validate when a template path can't be found" matches the main change. The raw summary and PR objectives both show that ValidateTemplates now returns an error when GetTemplatesPath cannot resolve a path and NotFoundCallback does not handle it, so nuclei -validate exits 1 for a missing path. The title is specific, follows conventional-commit style, and is under the length limit a teammate would scan easily. It does not cover the test additions, but that is expected.

Full details: Linked Issues check

Explanation

Issue #7949 requires a non-zero validation result when a -t path resolves to no template and no success report. ValidateTemplates now counts unresolved paths that NotFoundCallback does not handle and returns its validation error when the count is non-zero. The new missing-path test verifies an error and the missing-template log. The callback test preserves the accepted handled-path behavior. The closed issue #4866 supplies no active requirement.

Full details: Out of Scope Changes check

Explanation

The changes stay within issue #7949. The production change updates missing-path handling in ValidateTemplates. The test helper extraction and the two new tests support this behavior. Workflow handling uses the same existing validation path and does not add unrelated functionality.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 4 functions across 2 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

A rabbit checks each path in sight
Missing paths must fail outright
A callback may mark one handled
Then validation leaves it unscandalled
The logs record what could not be found
And success waits for paths that pass their round

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

@Mzack9999
Mzack9999 merged commit 26ce6d2 into projectdiscovery:dev Oct 27, 2026
33 of 34 checks passed
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.

-validate reports success and exits 0 when the template path does not exist

2 participants