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:
Abhisek Datta
2026-05-12 18:11:18 +05:30
committed by GitHub
parent 00fd6d2a9c
commit d993d57e3d
11 changed files with 830 additions and 60 deletions
+7 -19
View File
@@ -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)
}
+3 -9
View File
@@ -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)
}
}