Replace error constant with an error type

This commit is contained in:
Ice3man543 2021-08-28 00:21:07 +05:30
parent f5ea35d45c
commit 30f6498fe2
2 changed files with 7 additions and 7 deletions

View File

@ -2,7 +2,6 @@ package loader
import ( import (
"errors" "errors"
"strings"
"github.com/projectdiscovery/gologger" "github.com/projectdiscovery/gologger"
"github.com/projectdiscovery/nuclei/v2/internal/severity" "github.com/projectdiscovery/nuclei/v2/internal/severity"
@ -139,7 +138,7 @@ func areWorkflowOrTemplatesValid(store *Store, filteredTemplatePaths map[string]
} }
func isParsingError(message string, template string, err error) bool { func isParsingError(message string, template string, err error) bool {
if strings.Contains(err.Error(), templates.TemplateExecuterCreationErrorMessage) { if err == templates.ErrCreateTemplateExecutor {
return false return false
} }
if err == filter.ErrExcluded { if err == filter.ErrExcluded {

View File

@ -19,10 +19,11 @@ import (
"github.com/projectdiscovery/nuclei/v2/pkg/utils" "github.com/projectdiscovery/nuclei/v2/pkg/utils"
) )
const TemplateExecuterCreationErrorMessage = "cannot create template executer" var (
ErrCreateTemplateExecutor = errors.New("cannot create template executer")
var parsedTemplatesCache = cache.New() parsedTemplatesCache = cache.New()
var fieldErrorRegexp = regexp.MustCompile(`not found in`) fieldErrorRegexp = regexp.MustCompile(`not found in`)
)
// Parse parses a yaml request template file // Parse parses a yaml request template file
//nolint:gocritic // this cannot be passed by pointer //nolint:gocritic // this cannot be passed by pointer
@ -142,7 +143,7 @@ func Parse(filePath string, preprocessor Preprocessor, options protocols.Execute
template.TotalRequests += template.Executer.Requests() template.TotalRequests += template.Executer.Requests()
} }
if template.Executer == nil && template.CompiledWorkflow == nil { if template.Executer == nil && template.CompiledWorkflow == nil {
return nil, errors.New(TemplateExecuterCreationErrorMessage) return nil, ErrCreateTemplateExecutor
} }
template.Path = filePath template.Path = filePath