From 97f28d6e58971a50a69f8e31de640eccae88ac2a Mon Sep 17 00:00:00 2001 From: Fabian Mettler Date: Mon, 13 May 2024 22:58:57 +0200 Subject: [PATCH] cmd/incus/info: Fix runtime error when chassis, motherboard and firwmare information is not available Signed-off-by: Fabian Mettler --- cmd/incus/info.go | 72 +++++++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 33 deletions(-) diff --git a/cmd/incus/info.go b/cmd/incus/info.go index 3ed2c3a6ff..dc9c0e3dbe 100644 --- a/cmd/incus/info.go +++ b/cmd/incus/info.go @@ -415,53 +415,59 @@ func (c *cmdInfo) remoteInfo(d incus.InstanceServer) error { } // System: Chassis - fmt.Printf(i18n.G(" Chassis:") + "\n") - if resources.System.Chassis.Vendor != "" { - fmt.Printf(" "+i18n.G("Vendor: %s")+"\n", resources.System.Chassis.Vendor) - } + if resources.System.Chassis != nil { + fmt.Printf(i18n.G(" Chassis:") + "\n") + if resources.System.Chassis.Vendor != "" { + fmt.Printf(" "+i18n.G("Vendor: %s")+"\n", resources.System.Chassis.Vendor) + } - if resources.System.Chassis.Type != "" { - fmt.Printf(" "+i18n.G("Type: %s")+"\n", resources.System.Chassis.Type) - } + if resources.System.Chassis.Type != "" { + fmt.Printf(" "+i18n.G("Type: %s")+"\n", resources.System.Chassis.Type) + } - if resources.System.Chassis.Version != "" { - fmt.Printf(" "+i18n.G("Version: %s")+"\n", resources.System.Chassis.Version) - } + if resources.System.Chassis.Version != "" { + fmt.Printf(" "+i18n.G("Version: %s")+"\n", resources.System.Chassis.Version) + } - if resources.System.Chassis.Serial != "" { - fmt.Printf(" "+i18n.G("Serial: %s")+"\n", resources.System.Chassis.Serial) + if resources.System.Chassis.Serial != "" { + fmt.Printf(" "+i18n.G("Serial: %s")+"\n", resources.System.Chassis.Serial) + } } // System: Motherboard - fmt.Printf(i18n.G(" Motherboard:") + "\n") - if resources.System.Motherboard.Vendor != "" { - fmt.Printf(" "+i18n.G("Vendor: %s")+"\n", resources.System.Motherboard.Vendor) - } + if resources.System.Motherboard != nil { + fmt.Printf(i18n.G(" Motherboard:") + "\n") + if resources.System.Motherboard.Vendor != "" { + fmt.Printf(" "+i18n.G("Vendor: %s")+"\n", resources.System.Motherboard.Vendor) + } - if resources.System.Motherboard.Product != "" { - fmt.Printf(" "+i18n.G("Product: %s")+"\n", resources.System.Motherboard.Product) - } + if resources.System.Motherboard.Product != "" { + fmt.Printf(" "+i18n.G("Product: %s")+"\n", resources.System.Motherboard.Product) + } - if resources.System.Motherboard.Serial != "" { - fmt.Printf(" "+i18n.G("Serial: %s")+"\n", resources.System.Motherboard.Serial) - } + if resources.System.Motherboard.Serial != "" { + fmt.Printf(" "+i18n.G("Serial: %s")+"\n", resources.System.Motherboard.Serial) + } - if resources.System.Motherboard.Version != "" { - fmt.Printf(" "+i18n.G("Version: %s")+"\n", resources.System.Motherboard.Version) + if resources.System.Motherboard.Version != "" { + fmt.Printf(" "+i18n.G("Version: %s")+"\n", resources.System.Motherboard.Version) + } } // System: Firmware - fmt.Printf(i18n.G(" Firmware:") + "\n") - if resources.System.Firmware.Vendor != "" { - fmt.Printf(" "+i18n.G("Vendor: %s")+"\n", resources.System.Firmware.Vendor) - } + if resources.System.Firmware != nil { + fmt.Printf(i18n.G(" Firmware:") + "\n") + if resources.System.Firmware.Vendor != "" { + fmt.Printf(" "+i18n.G("Vendor: %s")+"\n", resources.System.Firmware.Vendor) + } - if resources.System.Firmware.Version != "" { - fmt.Printf(" "+i18n.G("Version: %s")+"\n", resources.System.Firmware.Version) - } + if resources.System.Firmware.Version != "" { + fmt.Printf(" "+i18n.G("Version: %s")+"\n", resources.System.Firmware.Version) + } - if resources.System.Firmware.Date != "" { - fmt.Printf(" "+i18n.G("Date: %s")+"\n", resources.System.Firmware.Date) + if resources.System.Firmware.Date != "" { + fmt.Printf(" "+i18n.G("Date: %s")+"\n", resources.System.Firmware.Date) + } } // Load