mirror of
https://github.com/safedep/pmg.git
synced 2026-08-03 07:24:09 +02:00
feat: Add support for sandbox diagnostic log (#245)
* feat: Add support for sandbox diagnostic log * fix: Normalize and prioritise sandbox violations * fix: Code review fixes
This commit is contained in:
@@ -22,6 +22,7 @@ import (
|
||||
"github.com/safedep/pmg/proxy"
|
||||
"github.com/safedep/pmg/proxy/certmanager"
|
||||
"github.com/safedep/pmg/proxy/interceptors"
|
||||
"github.com/safedep/pmg/sandbox"
|
||||
"github.com/safedep/pmg/sandbox/executor"
|
||||
"github.com/safedep/pmg/usefulerror"
|
||||
)
|
||||
@@ -394,7 +395,7 @@ func (f *proxyFlow) executeWithProxyForNonInteractiveTTY(
|
||||
|
||||
err = cmd.Run()
|
||||
if err != nil {
|
||||
return f.handlePackageManagerExecutionError(err)
|
||||
return f.handlePackageManagerExecutionError(err, result)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -547,33 +548,20 @@ func (f *proxyFlow) executeWithProxy(
|
||||
}
|
||||
|
||||
if sessionError != nil {
|
||||
return f.handlePackageManagerExecutionError(sessionError)
|
||||
return f.handlePackageManagerExecutionError(sessionError, result)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *proxyFlow) handlePackageManagerExecutionError(err error) error {
|
||||
func (f *proxyFlow) handlePackageManagerExecutionError(err error, result *sandbox.ExecutionResult) error {
|
||||
if exitErr, ok := err.(*exec.ExitError); ok {
|
||||
return usefulerror.Useful().
|
||||
WithCode(usefulerror.ErrCodePackageManagerExecutionFailed).
|
||||
WithHumanError(fmt.Sprintf("Package manager command exited with code: %d", exitErr.ExitCode())).
|
||||
WithHelp("Check the package manager command and its arguments").
|
||||
Wrap(err)
|
||||
return executor.WrapCommandExecutionError(err, result, exitErr.ExitCode())
|
||||
}
|
||||
|
||||
if sessionError, ok := err.(*pty.ExitError); ok {
|
||||
return usefulerror.Useful().
|
||||
WithCode(usefulerror.ErrCodePackageManagerExecutionFailed).
|
||||
WithHumanError(fmt.Sprintf("Package manager command exited with code: %d", sessionError.Code)).
|
||||
WithHelp("Check the package manager command and its arguments").
|
||||
Wrap(sessionError.Err)
|
||||
return executor.WrapCommandExecutionError(sessionError, result, sessionError.Code)
|
||||
}
|
||||
|
||||
return usefulerror.Useful().
|
||||
WithCode(usefulerror.ErrCodePackageManagerExecutionFailed).
|
||||
WithHumanError("Failed to execute package manager command").
|
||||
WithHelp("Check the package manager command and its arguments").
|
||||
Wrap(err)
|
||||
return executor.WrapCommandExecutionError(err, result, -1)
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"github.com/safedep/dry/log"
|
||||
"github.com/safedep/pmg/packagemanager"
|
||||
"github.com/safedep/pmg/sandbox/executor"
|
||||
"github.com/safedep/pmg/usefulerror"
|
||||
)
|
||||
|
||||
// Execute runs a package manager command without proxy or guard analysis.
|
||||
@@ -42,16 +41,11 @@ func Execute(ctx context.Context, pc *packagemanager.ParsedCommand, pmName strin
|
||||
|
||||
if result.ShouldRun() {
|
||||
if err := cmd.Run(); err != nil {
|
||||
humanError := "Failed to execute package manager command"
|
||||
exitCode := -1
|
||||
if exitErr, ok := err.(*exec.ExitError); ok {
|
||||
humanError = fmt.Sprintf("Package manager command exited with code: %d", exitErr.ExitCode())
|
||||
exitCode = exitErr.ExitCode()
|
||||
}
|
||||
|
||||
return usefulerror.Useful().
|
||||
WithCode(usefulerror.ErrCodePackageManagerExecutionFailed).
|
||||
WithHumanError(humanError).
|
||||
WithHelp("Check the package manager command and its arguments").
|
||||
Wrap(err)
|
||||
return executor.WrapCommandExecutionError(err, result, exitCode)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user