Skip to content

Commit e2d49b7

Browse files
authored
Silence showing the usage on error and fail on forced image verification (#459)
Signed-off-by: Radoslav Dimitrov <radoslav@stacklok.com>
1 parent 90c962b commit e2d49b7

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

cmd/thv/app/commands.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ func NewRootCmd() *cobra.Command {
5353
rootCmd.AddCommand(logsCommand())
5454
rootCmd.AddCommand(newSecretCommand())
5555

56+
// Silence printing the usage on error
57+
rootCmd.SilenceUsage = true
58+
5659
// Skip update check for completion command
5760
if !IsCompletionCommand(os.Args) {
5861
checkForUpdates()

cmd/thv/app/run.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,9 @@ func verifyImage(ctx context.Context, image string, rt runtime.Runtime, server *
315315
case verifyImageWarn, verifyImageEnabled:
316316
isSafe, err := rt.VerifyImage(ctx, server, image)
317317
if err != nil {
318-
// This happens if we have no provenance entry in the registry for this server. No need to fail, but do warn.
319-
if errors.Is(err, verifier.ErrProvenanceServerInformationNotSet) {
318+
// This happens if we have no provenance entry in the registry for this server.
319+
// Not finding provenance info in the registry is not a fatal error if the setting is "warn".
320+
if errors.Is(err, verifier.ErrProvenanceServerInformationNotSet) && verifySetting == verifyImageWarn {
320321
logger.Warnf("⚠️ MCP server %s has no provenance information set, skipping image verification", image)
321322
return nil
322323
}

cmd/thv/main.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
package main
33

44
import (
5-
"fmt"
65
"os"
76

87
"github.com/stacklok/toolhive/cmd/thv/app"
@@ -14,7 +13,6 @@ func main() {
1413
logger.Initialize()
1514

1615
if err := app.NewRootCmd().Execute(); err != nil {
17-
fmt.Fprintf(os.Stderr, "there was an error: %v\n", err)
1816
os.Exit(1)
1917
}
2018
}

0 commit comments

Comments
 (0)