Repository navigation
fix(loader): fail -validate when a template path can't be found - #7959
Conversation
`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
|
No actionable comments were generated in the recent review.
|
| 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:
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: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
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
#7949requires a non-zero validation result when a-tpath resolves to no template and no success report.ValidateTemplatesnow counts unresolved paths thatNotFoundCallbackdoes 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#4866supplies no active requirement.
Full details: Out of Scope Changes check
-
Explanation
The changes stay within issue
#7949. The production change updates missing-path handling inValidateTemplates. 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.
Proposed changes
Fixes #7949
nuclei -validate -t <path>logsCould not find templatefor a path that doesn't exist, then still printsAll templates validated successfullyand exits 0. A mistyped path in a CI step passes.Store.ValidateTemplatesignored the paths thatGetTemplatesPathcouldn't resolve.logErroredTemplatesnow returns how many of them were not handled byNotFoundCallback, andValidateTemplatesreturns 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
devand from this branch, same command:Before:
After:
Also checked with this branch:
All templates validated successfully, exit 0-t ok.yaml -t /tmp/nope.yaml): error, exit 1New tests in
pkg/catalog/loader/loader_test.go:TestValidateTemplatesRejectsMissingTemplatePathfails ondev("An error is expected but got nil") and passes here.TestValidateTemplatesAcceptsMissingPathHandledByCallbackcovers the callback case.newValidateStore, so the three tests share it.What I ran (Linux, Go 1.27.3):
go vetandgo test -count=1on./pkg/catalog/...and./internal/runner/..., all passing. I did not run the fullmake testor the integration suite.I used an AI assistant while working on this.
Checklist
Summary by CodeRabbit