From 9a2a7b749f41f73c2c11e4a4557516307838457b Mon Sep 17 00:00:00 2001 From: Ophestra Date: Mon, 3 Nov 2025 02:20:18 +0900 Subject: [PATCH] cmd/hakurei/print: handle nil config There is nothing to print in this case, and such a nil check is missing. Signed-off-by: Ophestra --- cmd/hakurei/print.go | 27 ++++++++++++++++----------- cmd/hakurei/print_test.go | 1 + 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/cmd/hakurei/print.go b/cmd/hakurei/print.go index c6f060a..5135858 100644 --- a/cmd/hakurei/print.go +++ b/cmd/hakurei/print.go @@ -44,7 +44,8 @@ func printShowSystem(output io.Writer, short, flagJSON bool) { func printShowInstance( output io.Writer, now time.Time, instance *hst.State, config *hst.Config, - short, flagJSON bool) (valid bool) { + short, flagJSON bool, +) (valid bool) { valid = true if flagJSON { @@ -66,6 +67,11 @@ func printShowInstance( } } + if config == nil { + // nothing to print + return + } + if instance != nil { t.Printf("State\n") t.Printf(" Instance:\t%s (%d -> %d)\n", instance.ID.String(), instance.PID, instance.ShimPID) @@ -84,14 +90,13 @@ func printShowInstance( t.Printf(" Groups:\t%s\n", strings.Join(config.Groups, ", ")) } if config.Container != nil { - params := config.Container - if params.Home != nil { - t.Printf(" Home:\t%s\n", params.Home) + if config.Container.Home != nil { + t.Printf(" Home:\t%s\n", config.Container.Home) } - if params.Hostname != "" { - t.Printf(" Hostname:\t%s\n", params.Hostname) + if config.Container.Hostname != "" { + t.Printf(" Hostname:\t%s\n", config.Container.Hostname) } - flags := params.Flags.String() + flags := config.Container.Flags.String() // this is included in the upper hst.Config struct but is relevant here const flagDirectWayland = "directwl" @@ -105,11 +110,11 @@ func printShowInstance( } t.Printf(" Flags:\t%s\n", flags) - if params.Path != nil { - t.Printf(" Path:\t%s\n", params.Path) + if config.Container.Path != nil { + t.Printf(" Path:\t%s\n", config.Container.Path) } - if len(params.Args) > 0 { - t.Printf(" Arguments:\t%s\n", strings.Join(params.Args, " ")) + if len(config.Container.Args) > 0 { + t.Printf(" Arguments:\t%s\n", strings.Join(config.Container.Args, " ")) } } t.Printf("\n") diff --git a/cmd/hakurei/print_test.go b/cmd/hakurei/print_test.go index 98ca806..b9344b5 100644 --- a/cmd/hakurei/print_test.go +++ b/cmd/hakurei/print_test.go @@ -59,6 +59,7 @@ func TestPrintShowInstance(t *testing.T) { want string valid bool }{ + {"nil", nil, nil, false, false, "Error: invalid configuration!\n\n", false}, {"config", nil, hst.Template(), false, false, `App Identity: 9 (org.chromium.Chromium) Enablements: wayland, dbus, pulseaudio