Skip to content

Commit

Permalink
commands: fix mismatch in argument error reporting
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
bboreham committed Feb 29, 2024
1 parent 513af1a commit 30a62f1
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions cmd/viewcore/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -728,21 +728,21 @@ 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 {
n = 256
} 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) {
Expand Down

0 comments on commit 30a62f1

Please sign in to comment.