Skip to content

Improve error message when template cannot be found#7245

Closed
Coder39179 wants to merge 3 commits intoprojectdiscovery:devfrom
Coder39179:improve-template-error-message
Closed

Improve error message when template cannot be found#7245
Coder39179 wants to merge 3 commits intoprojectdiscovery:devfrom
Coder39179:improve-template-error-message

Conversation

@Coder39179
Copy link

@Coder39179 Coder39179 commented Mar 17, 2026

Summary

Improves the error message shown when a template cannot be found.

The previous message did not provide clear guidance on how to resolve the issue.

Changes

  • Added instructions to run nuclei -update-templates
  • Added instructions to specify a templates directory with -t
  • Improved formatting for readability

Example Output

Before:
Could not find template 'cves/'

After:
Could not find template 'cves/'.
Details: could not find template file: no such path found: cves/

Ensure nuclei templates are installed by running:
nuclei -update-templates
Or specify the templates directory using:
-t /path/to/nuclei-templates

Summary by CodeRabbit

  • Bug Fixes
    • Improved error messaging for missing templates: users now see a clearer, multi-line guidance message with actionable steps to resolve missing template issues.
  • Style
    • Internal formatting/alignment updates for consistency; no change to user-facing behavior.

@auto-assign auto-assign bot requested a review from dogancanbakir March 17, 2026 02:57
@neo-by-projectdiscovery-dev
Copy link

neo-by-projectdiscovery-dev bot commented Mar 17, 2026

Neo - PR Security Review

No security issues found

Highlights

  • Fixed syntax error in workflow_loader.go line 74 that would have prevented compilation
  • Corrected malformed logging statement from previous commit to proper gologger.Warning().Msg(err.Error()) call
Hardening Notes
  • The error logging at line 74 now properly displays template loading errors to the CLI user running nuclei
  • Error messages are local CLI output shown only to the legitimate user, not exposed to remote attackers
  • The err.Error() string conversion is safe - no format string vulnerability since Msg() treats input as a literal message

Comment @pdneo help for available commands. · Open in Neo

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 17, 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: e42bc6a8-3f1a-4caf-8b1f-5936ded77474

📥 Commits

Reviewing files that changed from the base of the PR and between f028216 and fc8ad99.

📒 Files selected for processing (1)
  • pkg/loader/workflow/workflow_loader.go

Walkthrough

Added an exported constant MissingTemplateGuidance and updated missing-template log messages to use this constant; ExecutorOptions.Copy() was reformatted without behavioral changes.

Changes

Cohort / File(s) Summary
Loader constant & usage
pkg/catalog/loader/loader.go
Adds exported constant MissingTemplateGuidance containing a multi-line guidance message; logErroredTemplates updated to use this constant.
Workflow loader logging
pkg/loader/workflow/workflow_loader.go
Replaces inline "Could not find template" log messages in GetTemplatePathsByTags and GetTemplatePaths with loader.MissingTemplateGuidance (same formatting args).
Formatting: ExecutorOptions.Copy
pkg/protocols/protocols.go
Reformatted field initializers in ExecutorOptions.Copy() only; no functional or signature changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 I nudged a constant into the sun,

A clearer hint for templates that run.
Lines aligned, the copy's in tune,
We hop along — a tidy prune. 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Improve error message when template cannot be found' directly aligns with the primary change: adding a new MissingTemplateGuidance constant and updating error logging across multiple files to use clearer, more helpful guidance messages.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

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
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.

🧹 Nitpick comments (1)
pkg/loader/workflow/workflow_loader.go (1)

47-56: Centralize the missing-template guidance string to avoid drift.

The same multi-line message is duplicated in both methods (and mirrored in catalog loader). Extracting it into a shared const/helper will keep wording consistent and reduce maintenance cost.

♻️ Proposed refactor
+const missingTemplateGuidance = "Could not find template '%s'.\n" +
+	"Details: %s\n" +
+	"Ensure nuclei templates are installed by running:\n" +
+	"  nuclei -update-templates\n" +
+	"Or specify the templates directory using:\n" +
+	"  -t /path/to/nuclei-templates"
...
- gologger.Error().Msgf(
- 	"Could not find template '%s'.\n"+
- 		"Details: %s\n"+
- 		"Ensure nuclei templates are installed by running:\n"+
- 		"  nuclei -update-templates\n"+
- 		"Or specify the templates directory using:\n"+
- 		"  -t /path/to/nuclei-templates",
- 	template,
- 	err,
- )
+ gologger.Error().Msgf(missingTemplateGuidance, template, err)

Also applies to: 74-83

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/loader/workflow/workflow_loader.go` around lines 47 - 56, Duplicate
multi-line missing-template guidance should be centralized: add a single
exported const or helper (e.g., MissingTemplateMessage or
FormatMissingTemplateMessage(template string, err error)) in the loader package
and replace the inline Msgf usage in WorkflowLoader methods (the goroutine that
currently logs "Could not find template '%s'..." in workflow_loader.go) and the
equivalent code in the catalog loader to call that const/helper instead; ensure
the new helper accepts template and err (or returns a formatted string) and
update both call sites to use it so wording is consistent across loaders.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@pkg/loader/workflow/workflow_loader.go`:
- Around line 47-56: Duplicate multi-line missing-template guidance should be
centralized: add a single exported const or helper (e.g., MissingTemplateMessage
or FormatMissingTemplateMessage(template string, err error)) in the loader
package and replace the inline Msgf usage in WorkflowLoader methods (the
goroutine that currently logs "Could not find template '%s'..." in
workflow_loader.go) and the equivalent code in the catalog loader to call that
const/helper instead; ensure the new helper accepts template and err (or returns
a formatted string) and update both call sites to use it so wording is
consistent across loaders.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 29a2af93-63ab-4d07-a0a0-0448353f97b1

📥 Commits

Reviewing files that changed from the base of the PR and between 3497738 and 8921a19.

📒 Files selected for processing (2)
  • pkg/catalog/loader/loader.go
  • pkg/loader/workflow/workflow_loader.go

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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@pkg/loader/workflow/workflow_loader.go`:
- Line 74: The logging statement is malformed and uses wrong symbols; replace
the garbled call with a proper gologger call that references
loader.MissingTemplateGuidance and the loop variable templatePath, and include
the error via Err(err) instead of the invalid chained calls—e.g., call
gologger.Warning().Err(err).Msgf(loader.MissingTemplateGuidance, templatePath)
(or gologger.Error() if you want error level); ensure you remove the
duplicated/mangled tokens `Warninggologger.Error()` and the illegal
`()().Msg(...)` chaining and use the existing err and templatePath variables.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b0bade59-9caf-40e2-ba6b-7f36d2ad9f71

📥 Commits

Reviewing files that changed from the base of the PR and between 8921a19 and f028216.

📒 Files selected for processing (3)
  • pkg/catalog/loader/loader.go
  • pkg/loader/workflow/workflow_loader.go
  • pkg/protocols/protocols.go
✅ Files skipped from review due to trivial changes (1)
  • pkg/protocols/protocols.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/catalog/loader/loader.go

matched, err := w.options.Parser.LoadTemplate(templatePath, w.tagFilter, nil, w.options.Catalog)
if err != nil && !matched {
gologger.Warning().Msg(err.Error())
gologger.Warninggologger.Error().Msgf(missingTemplateGuidance, template, err)().Msg(err.Error())
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Critical: Malformed logging statement will cause compilation failure.

This line has multiple issues:

  1. gologger.Warninggologger.Error() is garbled syntax (looks like a merge conflict or copy-paste error)
  2. missingTemplateGuidance is undefined; should be loader.MissingTemplateGuidance
  3. template is not defined in this scope; the loop variable is templatePath
  4. The chained ()().Msg(err.Error()) is syntactically invalid

This code will not compile and would fail go vet.

🐛 Proposed fix
-		gologger.Warninggologger.Error().Msgf(missingTemplateGuidance, template, err)().Msg(err.Error())
+		gologger.Warning().Msgf(loader.MissingTemplateGuidance, templatePath, err)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
gologger.Warninggologger.Error().Msgf(missingTemplateGuidance, template, err)().Msg(err.Error())
gologger.Warning().Msgf(loader.MissingTemplateGuidance, templatePath, err)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/loader/workflow/workflow_loader.go` at line 74, The logging statement is
malformed and uses wrong symbols; replace the garbled call with a proper
gologger call that references loader.MissingTemplateGuidance and the loop
variable templatePath, and include the error via Err(err) instead of the invalid
chained calls—e.g., call
gologger.Warning().Err(err).Msgf(loader.MissingTemplateGuidance, templatePath)
(or gologger.Error() if you want error level); ensure you remove the
duplicated/mangled tokens `Warninggologger.Error()` and the illegal
`()().Msg(...)` chaining and use the existing err and templatePath variables.

@Coder39179
Copy link
Author

Refactored to centralize the missing-template guidance message and restored an unintentionally modified logging statement.

Copy link
Member

@dwisiswant0 dwisiswant0 left a comment

Choose a reason for hiding this comment

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

Before:
Could not find template 'cves/'

After:
Could not find template 'cves/'.
Details: could not find template file: no such path found: cves/

Ensure nuclei templates are installed by running:
nuclei -update-templates
Or specify the templates directory using:
-t /path/to/nuclei-templates

This does not improve anything nor add value.

The old message is already readable and idiomatic, which tells the user exactly which template failed and what the error was. That is guidance. For the vast majority of cases (missing file, perm issue, wrong path, etc.) this is clear, short, and sufficient.

Your new message is just hand-holding at the cost of code clarity and output noise.

The previous message did not provide clear guidance on how to resolve the issue.

That is simply not true nor a valid reason to add this patch.

We do not accept patches that turn simple, clear errors into verbose tutorials unless there is a demonstrated, frequent user confusion that justifies it.

@dwisiswant0
Copy link
Member

If the goal is to better educate users about missing templates, the right place for that is in the docs repo, not every error path in the code.

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.

2 participants