mirror of https://github.com/daffainfo/nuclei.git
Return wrapped errors for DSL compilation problems (#2492)
This allows the DSL help information to be printed when in debug mode. Fixes #2481dev
parent
e329428684
commit
62a4e0aa52
|
@ -872,3 +872,16 @@ func appendSingleDigitZero(value string) string {
|
||||||
}
|
}
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CompilationError struct {
|
||||||
|
DslSignature string
|
||||||
|
WrappedError error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *CompilationError) Error() string {
|
||||||
|
return fmt.Sprintf("could not compile DSL expression %q: %v", e.DslSignature, e.WrappedError)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *CompilationError) Unwrap() error {
|
||||||
|
return e.WrappedError
|
||||||
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ func (e *Extractor) CompileExtractors() error {
|
||||||
for _, dslExp := range e.DSL {
|
for _, dslExp := range e.DSL {
|
||||||
compiled, err := govaluate.NewEvaluableExpressionWithFunctions(dslExp, dsl.HelperFunctions)
|
compiled, err := govaluate.NewEvaluableExpressionWithFunctions(dslExp, dsl.HelperFunctions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not compile dsl: %s", dslExp)
|
return &dsl.CompilationError{DslSignature: dslExp, WrappedError: err}
|
||||||
}
|
}
|
||||||
e.dslCompiled = append(e.dslCompiled, compiled)
|
e.dslCompiled = append(e.dslCompiled, compiled)
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ func (matcher *Matcher) CompileMatchers() error {
|
||||||
for _, dslExpression := range matcher.DSL {
|
for _, dslExpression := range matcher.DSL {
|
||||||
compiledExpression, err := govaluate.NewEvaluableExpressionWithFunctions(dslExpression, dsl.HelperFunctions)
|
compiledExpression, err := govaluate.NewEvaluableExpressionWithFunctions(dslExpression, dsl.HelperFunctions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &DslCompilationError{DslSignature: dslExpression, WrappedError: err}
|
return &dsl.CompilationError{DslSignature: dslExpression, WrappedError: err}
|
||||||
}
|
}
|
||||||
matcher.dslCompiled = append(matcher.dslCompiled, compiledExpression)
|
matcher.dslCompiled = append(matcher.dslCompiled, compiledExpression)
|
||||||
}
|
}
|
||||||
|
@ -89,16 +89,3 @@ func (matcher *Matcher) CompileMatchers() error {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type DslCompilationError struct {
|
|
||||||
DslSignature string
|
|
||||||
WrappedError error
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *DslCompilationError) Error() string {
|
|
||||||
return fmt.Sprintf("could not compile DSL expression: %s. %v", e.DslSignature, e.WrappedError)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *DslCompilationError) Unwrap() error {
|
|
||||||
return e.WrappedError
|
|
||||||
}
|
|
||||||
|
|
|
@ -8,7 +8,6 @@ import (
|
||||||
|
|
||||||
"github.com/projectdiscovery/gologger"
|
"github.com/projectdiscovery/gologger"
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/operators/common/dsl"
|
"github.com/projectdiscovery/nuclei/v2/pkg/operators/common/dsl"
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/operators/matchers"
|
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/output"
|
"github.com/projectdiscovery/nuclei/v2/pkg/output"
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/protocols"
|
"github.com/projectdiscovery/nuclei/v2/pkg/protocols"
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/helpers/writer"
|
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/helpers/writer"
|
||||||
|
@ -33,7 +32,7 @@ func (e *Executer) Compile() error {
|
||||||
|
|
||||||
for _, request := range e.requests {
|
for _, request := range e.requests {
|
||||||
if err := request.Compile(e.options); err != nil {
|
if err := request.Compile(e.options); err != nil {
|
||||||
var dslCompilationError *matchers.DslCompilationError
|
var dslCompilationError *dsl.CompilationError
|
||||||
if errors.As(err, &dslCompilationError) {
|
if errors.As(err, &dslCompilationError) {
|
||||||
if cliOptions.Verbose {
|
if cliOptions.Verbose {
|
||||||
rawErrorMessage := dslCompilationError.Error()
|
rawErrorMessage := dslCompilationError.Error()
|
||||||
|
|
Loading…
Reference in New Issue