torrust-tracker
torrust-tracker copied to clipboard
Tracker Checker (HTTP): Improve error message when the JSON config is not well-formatted
Parent issue: https://github.com/torrust/torrust-tracker/issues/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
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.
Clients were extracted into a new package, bittorrent-tracker-client