mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-17 22:05:27 +00:00
Unwrap errors in json log output
This commit is contained in:
parent
463c1c0142
commit
1eb0378952
@ -16,6 +16,7 @@ import (
|
|||||||
"github.com/projectdiscovery/nuclei/v2/pkg/model"
|
"github.com/projectdiscovery/nuclei/v2/pkg/model"
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/model/types/severity"
|
"github.com/projectdiscovery/nuclei/v2/pkg/model/types/severity"
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/operators"
|
"github.com/projectdiscovery/nuclei/v2/pkg/operators"
|
||||||
|
"github.com/projectdiscovery/nuclei/v2/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Writer is an interface which writes output to somewhere for nuclei events.
|
// Writer is an interface which writes output to somewhere for nuclei events.
|
||||||
@ -192,8 +193,8 @@ func (w *StandardWriter) Request(templatePath, input, requestType string, reques
|
|||||||
Input: input,
|
Input: input,
|
||||||
Type: requestType,
|
Type: requestType,
|
||||||
}
|
}
|
||||||
if requestErr != nil {
|
if unwrappedErr := utils.UnwrapError(requestErr); unwrappedErr != nil {
|
||||||
request.Error = requestErr.Error()
|
request.Error = unwrappedErr.Error()
|
||||||
} else {
|
} else {
|
||||||
request.Error = "none"
|
request.Error = "none"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -11,3 +12,14 @@ func IsBlank(value string) bool {
|
|||||||
func IsNotBlank(value string) bool {
|
func IsNotBlank(value string) bool {
|
||||||
return !IsBlank(value)
|
return !IsBlank(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func UnwrapError(err error) error {
|
||||||
|
for { // get the last wrapped error
|
||||||
|
unwrapped := errors.Unwrap(err)
|
||||||
|
if unwrapped == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
err = unwrapped
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|||||||
21
v2/pkg/utils/utils_test.go
Normal file
21
v2/pkg/utils/utils_test.go
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestUnwrapError(t *testing.T) {
|
||||||
|
require.Equal(t, nil, UnwrapError(nil))
|
||||||
|
|
||||||
|
errOne := fmt.Errorf("error one")
|
||||||
|
require.Equal(t, errOne, UnwrapError(errOne))
|
||||||
|
|
||||||
|
errTwo := fmt.Errorf("error with error: %w", errOne)
|
||||||
|
require.Equal(t, errOne, UnwrapError(errTwo))
|
||||||
|
|
||||||
|
errThree := fmt.Errorf("error with error: %w", errTwo)
|
||||||
|
require.Equal(t, errOne, UnwrapError(errThree))
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user