bitmagnet-io / bitmagnet

A self-hosted BitTorrent indexer, DHT crawler, content classifier and torrent search engine with web UI, GraphQL API and Servarr stack integration.
https://bitmagnet.io/
MIT License
2.47k stars 100 forks source link

CLI help doesn't work well without a working configuration #76

Closed viraptor closed 10 months ago

viraptor commented 11 months ago

Have you checked the roadmap on the website, and existing issues, before opening a dupllcate issue? Yes

Describe the bug Multiple CLI commands for bitmagnet cause numerous errors due to lack of working configuration before/instead of giving the help output expected.

To Reproduce

  1. Run postgres/redis in non-default location.
  2. Have a copy of bitmagnet daemon running.
  3. Run bitmagnet config --help
  4. Get:
    ERROR   migrations/decorator.go:31      failed to ping database: failed to connect to `host=localhost user=postgres database=bitmagnet`: server error (FATAL: no pg_hba.conf entry for host "127.0.0.1", user "postgres", database "bitmagnet", no encryption (SQLSTATE 28000))
    github.com/bitmagnet-io/bitmagnet/internal/database/migrations.NewDecorator
    ...
    WARN    tmdb_client     tmdb/client.go:40       you are using the default TMDB api key; TMDB requests will be limited to 1 per second; to remove this warning please configure a personal TMDB api key
    2023/11/27 10:58:06 Failed to collect metrics data: failed to get queue names: dial tcp [::1]:6379: connect: connection refused
    ERROR   fx      fxevent/zap.go:59       OnStart hook failed     {"callee": "github.com/bitmagnet-io/bitmagnet/internal/protocol/dht/server.New.func1()", "caller": "github.com/bitmagnet-io/bitmagnet/internal/boilerplate/cli/hooks.New", "error": "could not open socket: address already in use"}
    ...
    ERROR   fx      fxevent/zap.go:59       start failed, rolling back      {"error": "could not open socket: address already in use"}
    ...
    ERROR   fx      fxevent/zap.go:59       start failed    {"error": "could not open socket: address already in use"}

Expected behavior Display the help output for that command without any attempts to connect to the databases.

General (please complete the following information):

mgdigital commented 11 months ago

Thanks, I'm aware of this - it's a tricky one to fix, due to some inflexibilities in the FX framework, which is geared towards long-running processes with a fixed set of dependencies, not really to a CLI app like this. It's annoying as there's a lot to like about FX and it seems there aren't many other good options for dependency injection in GoLang...

A workaround is probably possible but not trivial. It might be a case of removing the CLI altogether and driving everything through the API and GUI...