Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Datree
Commits
d7c82208
Commit
d7c82208
authored
3 years ago
by
Ben Zaad
Browse files
Options
Download
Email Patches
Plain Diff
feat: report unexpected errors to server
parent
08069ea5
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
bl/errorReporter/errorReporter.go
+10
-5
bl/errorReporter/errorReporter.go
bl/errorReporter/errorReporter_test.go
+2
-2
bl/errorReporter/errorReporter_test.go
main.go
+2
-1
main.go
pkg/cliClient/reportCliError.go
+2
-2
pkg/cliClient/reportCliError.go
with
16 additions
and
10 deletions
+16
-10
bl/errorReporter/errorReporter.go
+
10
-
5
View file @
d7c82208
...
...
@@ -12,9 +12,14 @@ import (
"github.com/datreeio/datree/pkg/localConfig"
)
func
ReportCliError
(
panicErr
interface
{})
{
func
ReportCli
Panic
Error
(
panicErr
interface
{})
{
reporter
:=
NewErrorReporter
(
cliClient
.
NewCliClient
(
deploymentConfig
.
URL
),
localConfig
.
NewLocalConfig
(),
printer
.
CreateNewPrinter
())
reporter
.
ReportCliError
(
panicErr
)
reporter
.
ReportCliError
(
panicErr
,
"/report-cli-panic-error"
)
}
func
ReportCliUnexpectedError
(
unexpectedError
error
)
{
reporter
:=
NewErrorReporter
(
cliClient
.
NewCliClient
(
deploymentConfig
.
URL
),
localConfig
.
NewLocalConfig
(),
printer
.
CreateNewPrinter
())
reporter
.
ReportCliError
(
unexpectedError
,
"/report-cli-unexpected-error"
)
}
type
LocalConfig
interface
{
...
...
@@ -22,7 +27,7 @@ type LocalConfig interface {
}
type
CliClient
interface
{
ReportCliError
(
reportCliErrorRequest
cliClient
.
ReportCliErrorRequest
)
(
StatusCode
int
,
Error
error
)
ReportCliError
(
reportCliErrorRequest
cliClient
.
ReportCliErrorRequest
,
uri
string
)
(
StatusCode
int
,
Error
error
)
}
type
Printer
interface
{
...
...
@@ -43,7 +48,7 @@ func NewErrorReporter(client CliClient, localConfig LocalConfig, printer Printer
}
}
func
(
reporter
*
ErrorReporter
)
ReportCliError
(
panicErr
interface
{})
{
func
(
reporter
*
ErrorReporter
)
ReportCliError
(
panicErr
interface
{}
,
uri
string
)
{
errorMessage
:=
parsePanicError
(
panicErr
)
cliId
:=
reporter
.
getCliId
()
_
,
err
:=
reporter
.
client
.
ReportCliError
(
cliClient
.
ReportCliErrorRequest
{
...
...
@@ -52,7 +57,7 @@ func (reporter *ErrorReporter) ReportCliError(panicErr interface{}) {
CliVersion
:
cmd
.
CliVersion
,
ErrorMessage
:
errorMessage
,
StackTrace
:
string
(
debug
.
Stack
()),
})
}
,
uri
)
if
err
!=
nil
{
// do nothing
}
...
...
This diff is collapsed.
Click to expand it.
bl/errorReporter/errorReporter_test.go
+
2
-
2
View file @
d7c82208
...
...
@@ -17,7 +17,7 @@ type mockCliClient struct {
mock
.
Mock
}
func
(
m
*
mockCliClient
)
ReportCliError
(
reportCliErrorRequest
cliClient
.
ReportCliErrorRequest
)
(
StatusCode
int
,
Error
error
)
{
func
(
m
*
mockCliClient
)
ReportCliError
(
reportCliErrorRequest
cliClient
.
ReportCliErrorRequest
,
uri
string
)
(
StatusCode
int
,
Error
error
)
{
m
.
Called
(
reportCliErrorRequest
)
return
201
,
nil
}
...
...
@@ -73,7 +73,7 @@ func TestErrorReporter(t *testing.T) {
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
errorReporter
.
ReportCliError
(
tt
.
args
.
panicErr
)
errorReporter
.
ReportCliError
(
tt
.
args
.
panicErr
,
"/report-cli-panic-error"
)
reportCliErrorCalledArgs
:=
(
mockedCliClient
.
Calls
[
0
]
.
Arguments
.
Get
(
0
))
.
(
cliClient
.
ReportCliErrorRequest
)
assert
.
Equal
(
t
,
tt
.
expected
.
ErrorMessage
,
reportCliErrorCalledArgs
.
ErrorMessage
)
assert
.
Equal
(
t
,
tt
.
expected
.
ClientId
,
reportCliErrorCalledArgs
.
ClientId
)
...
...
This diff is collapsed.
Click to expand it.
main.go
+
2
-
1
View file @
d7c82208
...
...
@@ -16,7 +16,7 @@ func main() {
// global error handling
defer
func
()
{
if
panicErr
:=
recover
();
panicErr
!=
nil
{
errorReporter
.
ReportCliError
(
panicErr
)
errorReporter
.
ReportCli
Panic
Error
(
panicErr
)
os
.
Exit
(
DEFAULT_ERR_EXIT_CODE
)
}
}()
...
...
@@ -25,6 +25,7 @@ func main() {
if
errors
.
Is
(
err
,
test
.
ViolationsFoundError
)
{
os
.
Exit
(
VIOLATIONS_FOUND_EXIT_CODE
)
}
errorReporter
.
ReportCliUnexpectedError
(
err
)
os
.
Exit
(
DEFAULT_ERR_EXIT_CODE
)
}
}
This diff is collapsed.
Click to expand it.
pkg/cliClient/reportCliError.go
+
2
-
2
View file @
d7c82208
...
...
@@ -12,11 +12,11 @@ type ReportCliErrorRequest struct {
StackTrace
string
`json:"stackTrace"`
}
func
(
c
*
CliClient
)
ReportCliError
(
reportCliErrorRequest
ReportCliErrorRequest
)
(
StatusCode
int
,
Error
error
)
{
func
(
c
*
CliClient
)
ReportCliError
(
reportCliErrorRequest
ReportCliErrorRequest
,
uri
string
)
(
StatusCode
int
,
Error
error
)
{
headers
:=
map
[
string
]
string
{}
res
,
err
:=
c
.
httpClient
.
Request
(
http
.
MethodPost
,
"/cli/public/
report-cli-error"
,
"/cli/public/
"
+
uri
,
reportCliErrorRequest
,
headers
,
)
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment