Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracker Checker (HTTP): Improve error message when the JSON config is not well-formatted #1042

Open
Tracked by #669
josecelano opened this issue Sep 12, 2024 · 2 comments
Labels
Easy Good for Newcomers Enhancement / Feature Request Something New

Comments

@josecelano
Copy link
Member

Parent issue: #669

When you run the checker for more than one HTTP tracker and it fails, it only shows an error but not the cause.

How to reproduce

Run the checker without running the tracker:

TORRUST_CHECKER_CONFIG='{
    "udp_trackers": [],
    "http_trackers": [
	"http://127.0.0.1:7070",
	"http://127.0.0.1:7070/",
	"http://127.0.0.1:7070/announce",
    ],
    "health_checks": []
}' cargo run --bin tracker_checker
    Finished `dev` profile [optimized + debuginfo] target(s) in 0.09s
     Running `target/debug/tracker_checker`
thread 'main' panicked at src/bin/tracker_checker.rs:6:22:
Some checks fail: invalid config format

Caused by:
    JSON parse error: trailing comma at line 7 column 5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
@josecelano josecelano mentioned this issue Sep 12, 2024
21 tasks
@josecelano josecelano changed the title Tracker Checker (HTTP): Shoe failed checks Tracker Checker (HTTP): Don't show failed checks Sep 12, 2024
@josecelano
Copy link
Member Author

I was wrong. It works:

$ TORRUST_CHECKER_CONFIG='{
    "udp_trackers": [],
    "http_trackers": [
        "http://127.0.0.1:7070",
        "http://127.0.0.1:7070/",
        "http://127.0.0.1:7070/announce"
    ],
    "health_checks": []
}' cargo run --bin tracker_checker
    Finished `dev` profile [optimized + debuginfo] target(s) in 0.09s
     Running `target/debug/tracker_checker`
2024-09-12T16:19:33.637563Z  INFO torrust_tracker::console::clients::checker::service: Running checks for trackers ...
[
  {
    "Http": {
      "Err": {
        "url": "http://127.0.0.1:7070/",
        "results": [
          [
            "Announce",
            {
              "Err": "Http request did not receive a response within the timeout: ResponseError { err: reqwest::Error { kind: Request, url: \"http://127.0.0.1:7070/announce?info_hash=%9C8B%22%13%E3%0B%FF%21%2B0%C3%60%D2o%9A%02%13d%22&peer_addr=192.168.1.88&downloaded=0&uploaded=0&peer_id=%2DqB00000000000000001&port=17548&left=0&event=completed&compact=0\", source: hyper_util::client::legacy::Error(Connect, ConnectError(\"tcp connect error\", Os { code: 111, kind: ConnectionRefused, message: \"Connection refused\" })) } }"
            }
          ],
          [
            "Scrape",
            {
              "Err": "Http request did not receive a response within the timeout: ResponseError { err: reqwest::Error { kind: Request, url: \"http://127.0.0.1:7070/scrape?info_hash=%9C8B%22%13%E3%0B%FF%21%2B0%C3%60%D2o%9A%02%13d%22\", source: hyper_util::client::legacy::Error(Connect, ConnectError(\"tcp connect error\", Os { code: 111, kind: ConnectionRefused, message: \"Connection refused\" })) } }"
            }
          ]
        ]
      }
    }
  },
  {
    "Http": {
      "Err": {
        "url": "http://127.0.0.1:7070/",
        "results": [
          [
            "Announce",
            {
              "Err": "Http request did not receive a response within the timeout: ResponseError { err: reqwest::Error { kind: Request, url: \"http://127.0.0.1:7070/announce?info_hash=%9C8B%22%13%E3%0B%FF%21%2B0%C3%60%D2o%9A%02%13d%22&peer_addr=192.168.1.88&downloaded=0&uploaded=0&peer_id=%2DqB00000000000000001&port=17548&left=0&event=completed&compact=0\", source: hyper_util::client::legacy::Error(Connect, ConnectError(\"tcp connect error\", Os { code: 111, kind: ConnectionRefused, message: \"Connection refused\" })) } }"
            }
          ],
          [
            "Scrape",
            {
              "Err": "Http request did not receive a response within the timeout: ResponseError { err: reqwest::Error { kind: Request, url: \"http://127.0.0.1:7070/scrape?info_hash=%9C8B%22%13%E3%0B%FF%21%2B0%C3%60%D2o%9A%02%13d%22\", source: hyper_util::client::legacy::Error(Connect, ConnectError(\"tcp connect error\", Os { code: 111, kind: ConnectionRefused, message: \"Connection refused\" })) } }"
            }
          ]
        ]
      }
    }
  },
  {
    "Http": {
      "Err": {
        "url": "http://127.0.0.1:7070/announce",
        "results": [
          [
            "Announce",
            {
              "Err": "Http request did not receive a response within the timeout: ResponseError { err: reqwest::Error { kind: Request, url: \"http://127.0.0.1:7070/announce?info_hash=%9C8B%22%13%E3%0B%FF%21%2B0%C3%60%D2o%9A%02%13d%22&peer_addr=192.168.1.88&downloaded=0&uploaded=0&peer_id=%2DqB00000000000000001&port=17548&left=0&event=completed&compact=0\", source: hyper_util::client::legacy::Error(Connect, ConnectError(\"tcp connect error\", Os { code: 111, kind: ConnectionRefused, message: \"Connection refused\" })) } }"
            }
          ],
          [
            "Scrape",
            {
              "Err": "Http request did not receive a response within the timeout: ResponseError { err: reqwest::Error { kind: Request, url: \"http://127.0.0.1:7070/scrape?info_hash=%9C8B%22%13%E3%0B%FF%21%2B0%C3%60%D2o%9A%02%13d%22\", source: hyper_util::client::legacy::Error(Connect, ConnectError(\"tcp connect error\", Os { code: 111, kind: ConnectionRefused, message: \"Connection refused\" })) } }"
            }
          ]
        ]
      }
    }
  }
]

The problem was an extra comma in the JSON configuration. That broke the JSON, and the checker couldn't parse the configuration.

This is the right command:

TORRUST_CHECKER_CONFIG='{
    "udp_trackers": [],
    "http_trackers": [
	"http://127.0.0.1:7070",
	"http://127.0.0.1:7070/",
	"http://127.0.0.1:7070/announce"
    ],
    "health_checks": []
}' cargo run --bin tracker_checker

I'm going to keep the issue to improve the error message. For example:

"invalid JSON config format"

Maybe we can show the serde error if the message is more concrete.

@josecelano josecelano changed the title Tracker Checker (HTTP): Don't show failed checks Tracker Checker (HTTP): Improve error message when the JSON config is not well-formated Sep 12, 2024
@josecelano josecelano changed the title Tracker Checker (HTTP): Improve error message when the JSON config is not well-formated Tracker Checker (HTTP): Improve error message when the JSON config is not well-formatted Sep 12, 2024
@josecelano josecelano added the Easy Good for Newcomers label Oct 17, 2024
@josecelano
Copy link
Member Author

Clients were extracted into a new package, bittorrent-tracker-client

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Easy Good for Newcomers Enhancement / Feature Request Something New
Projects
None yet
Development

No branches or pull requests

1 participant