feat: add documentation URL for database lock errors (#9531)

This commit is contained in:
Teppei Fukuda
2025-09-26 12:25:44 +04:00
committed by GitHub
parent 92ebc7e4d7
commit eba48afd58
5 changed files with 37 additions and 20 deletions

33
pkg/commands/run.go Normal file
View File

@@ -0,0 +1,33 @@
package commands
import (
"context"
"errors"
"fmt"
bberrors "go.etcd.io/bbolt/errors"
"github.com/aquasecurity/trivy/pkg/log"
"github.com/aquasecurity/trivy/pkg/version/doc"
)
const (
troubleshootingDocPath = "/docs/references/troubleshooting/"
lockDocFragment = "database-and-cache-lock-errors"
timeoutDocFragment = "timeout"
)
// Run builds the CLI application and executes it with centralized error handling.
func Run(ctx context.Context) error {
app := NewApp()
if err := app.ExecuteContext(ctx); err != nil {
if errors.Is(err, context.DeadlineExceeded) {
log.WarnContext(ctx, fmt.Sprintf("Provide a higher timeout value, see %s", doc.URL(troubleshootingDocPath, timeoutDocFragment)))
}
if errors.Is(err, bberrors.ErrTimeout) {
log.ErrorContext(ctx, fmt.Sprintf("Failed to acquire cache or database lock, see %s for troubleshooting", doc.URL(troubleshootingDocPath, lockDocFragment)))
}
return err
}
return nil
}