direct-connect / go-dcpp

Hybrid Direct Connect hub written in Go.
BSD 3-Clause "New" or "Revised" License
36 stars 9 forks source link

Avoid exception and return a formatting error if encoding is unknown #90

Closed Kcchouette closed 4 years ago

Kcchouette commented 5 years ago

example:

$ /home/user/go-dcpp/dcping ping besthub.ro --encoding=1252
Error: htmlindex: invalid encoding name
Usage:
  dcping ping [proto://]host[:port] [...] [flags]

Flags:
      --debug              print protocol messages to stderr
  -e, --encoding string    fallback encoding
      --files int          declared share files
  -h, --help               help for ping
      --hubs int           declared hub count
      --name string        name of the pinger
  -n, --num int            number of parallel pings (default 4)
      --out string         output format (json, xml or xml-line) (default "json")
      --pretty             pretty-print an output
      --share uint         declared share size (in bytes)
      --slots int          declared slots
  -t, --timeout duration   ping timeout (default 5s)
      --users              return user list as well

htmlindex: invalid encoding name
dennwc commented 5 years ago

Can you please clarify what you expect here?

Kcchouette commented 5 years ago

I expect no this kind of error, more like:

$ /home/user/go-dcpp/dcping ping besthub.ro --encoding=1252
Error: arg --encoding invalid encoding name

Or even

$ /home/user/go-dcpp/dcping ping besthub.ro --encoding=1252
{"status":"error", "errcode":227}

Where 227 correspond to "invalid encoding name"

dennwc commented 4 years ago

Implemented the first option