Skip to content

Commit

Permalink
chore: better error handling
Browse files Browse the repository at this point in the history
Signed-off-by: Norman <[email protected]>
  • Loading branch information
n0izn0iz committed Dec 28, 2024
1 parent 3a519b3 commit 8b1ddaf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions gnovm/cmd/gno/pkgaddr.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"context"
"fmt"
"flag"

"github.com/gnolang/gno/gnovm/pkg/gnolang"
"github.com/gnolang/gno/tm2/pkg/commands"
Expand All @@ -24,7 +24,7 @@ func newPkgAddrCmd(io commands.IO) *commands.Command {

func execPkgAddr(args []string, io commands.IO) error {
if len(args) != 1 {
return fmt.Errorf("expected 1 arg, got %d", len(args))
return flag.ErrHelp
}

io.Println(gnolang.DerivePkgAddr(args[0]))
Expand Down
9 changes: 7 additions & 2 deletions gnovm/cmd/gno/pkgaddr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ import (
func TestPkgAddrApp(t *testing.T) {
tc := []testMainCase{
{
args: []string{"pkgaddr"},
errShouldBe: "expected 1 arg, got 0",
args: []string{"pkgaddr"},
errShouldContain: "flag: help requested",
},

{
args: []string{"pkgaddr", "bli", "blu"},
errShouldContain: "flag: help requested",
},

{
Expand Down

0 comments on commit 8b1ddaf

Please sign in to comment.