From 30a62f16a6c0e41b74613e8de7e61405df6794af Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Thu, 29 Feb 2024 19:22:48 +0000 Subject: [PATCH] commands: fix mismatch in argument error reporting Also do the initial parsing earlier, to save effort reading the core if we can't proceed. Signed-off-by: Bryan Boreham --- cmd/viewcore/main.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/cmd/viewcore/main.go b/cmd/viewcore/main.go index 9f0d999..51a5cd1 100644 --- a/cmd/viewcore/main.go +++ b/cmd/viewcore/main.go @@ -616,18 +616,18 @@ func runObjects(cmd *cobra.Command, args []string) { } func runReachable(cmd *cobra.Command, args []string) { - _, c, err := readCore() + n, err := strconv.ParseInt(args[0], 16, 64) if err != nil { - exitf("%v\n", err) + exitf("can't parse %q as an object address\n", args[0]) } - n, err := strconv.ParseInt(args[0], 16, 64) + _, c, err := readCore() if err != nil { - exitf("can't parse %q as an object address\n", args[1]) + exitf("%v\n", err) } a := core.Address(n) obj, _ := c.FindObject(a) if obj == 0 { - exitf("can't find object at address %s\n", args[1]) + exitf("can't find object at address %s\n", args[0]) } // Breadth-first search backwards until we reach a root. @@ -728,13 +728,13 @@ func runHTML(cmd *cobra.Command, args []string) { } func runRead(cmd *cobra.Command, args []string) { - p, _, err := readCore() + n, err := strconv.ParseInt(args[0], 16, 64) if err != nil { - exitf("%v\n", err) + exitf("can't parse %q as an object address\n", args[0]) } - n, err := strconv.ParseInt(args[0], 16, 64) + p, _, err := readCore() if err != nil { - exitf("can't parse %q as an object address\n", args[1]) + exitf("%v\n", err) } a := core.Address(n) if len(args) < 2 { @@ -742,7 +742,7 @@ func runRead(cmd *cobra.Command, args []string) { } else { n, err = strconv.ParseInt(args[1], 10, 64) if err != nil { - exitf("can't parse %q as a byte count\n", args[2]) + exitf("can't parse %q as a byte count\n", args[1]) } } if !p.ReadableN(a, n) {