hostctl icon indicating copy to clipboard operation
hostctl copied to clipboard

runtime error

Open Zaffy opened this issue 3 years ago • 0 comments

Describe the bug

A line in hosts file causes runtime error:

panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
github.com/guumaster/hostctl/pkg/parser.parseToDefault({0xc00042213c, 0x9, 0xec4}, {0x0, 0x55c8d424ac5b})
        github.com/guumaster/hostctl/pkg/parser/parser.go:116 +0x1dc
github.com/guumaster/hostctl/pkg/parser.Parse({0x55c8d4861aa0, 0xc00019c4b0})
        github.com/guumaster/hostctl/pkg/parser/parser.go:67 +0x48a
github.com/guumaster/hostctl/pkg/file.NewWithFs({0x55c8d45681f5, 0x55c8d4567e4c}, {0x55c8d48724f8, 0x55c8d4b2da28})
        github.com/guumaster/hostctl/pkg/file/file.go:43 +0x10a
github.com/guumaster/hostctl/pkg/file.NewFile(...)
        github.com/guumaster/hostctl/pkg/file/file.go:26
github.com/guumaster/hostctl/cmd/hostctl/actions.newListCmd.func1(0xc00041e580, {0x55c8d4b2da28, 0x0, 0x0})
        github.com/guumaster/hostctl/cmd/hostctl/actions/list.go:24 +0x5f
github.com/spf13/cobra.(*Command).execute(0xc00041e580, {0x55c8d4b2da28, 0x0, 0x0})
        github.com/spf13/[email protected]/command.go:842 +0x60e
github.com/spf13/cobra.(*Command).ExecuteC(0xc0001c6dc0)
        github.com/spf13/[email protected]/command.go:950 +0x3ad
github.com/spf13/cobra.(*Command).Execute(...)
        github.com/spf13/[email protected]/command.go:887
main.main()
        ./main.go:19 +0x76

To Reproduce Steps to reproduce the behavior:

echo '# 1.1.1.1' > /tmp/hosts
hostctl --host-file /tmp/hosts list

Expected behavior A clear and concise description of what you expected to happen.

The line should be treated as comment and not crash.

System (please complete the following information):

  • archlinux
  • aur / hostctl version 1.1.1

Zaffy avatar Mar 08 '22 12:03 Zaffy