Skip to content

Commit 30a62f1

Browse files
committed
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 <bjboreham@gmail.com>
1 parent 513af1a commit 30a62f1

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

cmd/viewcore/main.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -616,18 +616,18 @@ func runObjects(cmd *cobra.Command, args []string) {
616616
}
617617

618618
func runReachable(cmd *cobra.Command, args []string) {
619-
_, c, err := readCore()
619+
n, err := strconv.ParseInt(args[0], 16, 64)
620620
if err != nil {
621-
exitf("%v\n", err)
621+
exitf("can't parse %q as an object address\n", args[0])
622622
}
623-
n, err := strconv.ParseInt(args[0], 16, 64)
623+
_, c, err := readCore()
624624
if err != nil {
625-
exitf("can't parse %q as an object address\n", args[1])
625+
exitf("%v\n", err)
626626
}
627627
a := core.Address(n)
628628
obj, _ := c.FindObject(a)
629629
if obj == 0 {
630-
exitf("can't find object at address %s\n", args[1])
630+
exitf("can't find object at address %s\n", args[0])
631631
}
632632

633633
// Breadth-first search backwards until we reach a root.
@@ -728,21 +728,21 @@ func runHTML(cmd *cobra.Command, args []string) {
728728
}
729729

730730
func runRead(cmd *cobra.Command, args []string) {
731-
p, _, err := readCore()
731+
n, err := strconv.ParseInt(args[0], 16, 64)
732732
if err != nil {
733-
exitf("%v\n", err)
733+
exitf("can't parse %q as an object address\n", args[0])
734734
}
735-
n, err := strconv.ParseInt(args[0], 16, 64)
735+
p, _, err := readCore()
736736
if err != nil {
737-
exitf("can't parse %q as an object address\n", args[1])
737+
exitf("%v\n", err)
738738
}
739739
a := core.Address(n)
740740
if len(args) < 2 {
741741
n = 256
742742
} else {
743743
n, err = strconv.ParseInt(args[1], 10, 64)
744744
if err != nil {
745-
exitf("can't parse %q as a byte count\n", args[2])
745+
exitf("can't parse %q as a byte count\n", args[1])
746746
}
747747
}
748748
if !p.ReadableN(a, n) {

0 commit comments

Comments
 (0)