Added enhanced diagnostics for torrent list retrieval

- Added verbose logging to identify when no torrents are found
- Added raw transmission command output logging to troubleshoot connection issues
- Improved tracking of torrent ID extraction from command output
- Made torrent count always visible, not just in debug mode

🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
masterdraco 2025-03-04 18:12:11 +01:00
parent e64e1115a7
commit 1119f38fd6
2 changed files with 30 additions and 5 deletions

View File

@ -118,11 +118,18 @@ main() {
log_debug "Getting list of torrents..." log_debug "Getting list of torrents..."
local torrent_ids local torrent_ids
torrent_ids=$(get_torrents) torrent_ids=$(get_torrents)
log_debug "Found $(echo "$torrent_ids" | wc -l) torrents" log_info "Found $(echo "$torrent_ids" | wc -l) torrents"
# Use a regular for loop instead of a pipe to while # Use a regular for loop instead of a pipe to while
# to avoid the subshell issue that causes processed_source_dirs to be lost # to avoid the subshell issue that causes processed_source_dirs to be lost
readarray -t torrent_ids_array <<< "$torrent_ids" readarray -t torrent_ids_array <<< "$torrent_ids"
# Print the torrent IDs to debug (always, not just in debug mode)
if [[ ${#torrent_ids_array[@]} -eq 0 ]]; then
log_info "No torrents found to process"
else
log_info "Torrent IDs to process: ${torrent_ids_array[*]}"
fi
for id in "${torrent_ids_array[@]}"; do for id in "${torrent_ids_array[@]}"; do
# Skip empty IDs # Skip empty IDs
if [[ -z "$id" ]]; then if [[ -z "$id" ]]; then

View File

@ -113,15 +113,33 @@ process_removal() {
# get_torrents: Retrieves a list of torrents from Transmission # get_torrents: Retrieves a list of torrents from Transmission
get_torrents() { get_torrents() {
local cmd="transmission-remote ${TRANSMISSION_IP}:${TRANSMISSION_PORT} -n ${TRANSMISSION_USER}:${TRANSMISSION_PASSWORD} -l" # Log the full command we're about to run, sensitive info redacted for logging
log_debug "Running command: $cmd" local cmd_display="transmission-remote ${TRANSMISSION_IP}:${TRANSMISSION_PORT} -n [redacted] -l"
log_info "Running command: $cmd_display"
# Execute the actual command
local real_cmd="transmission-remote ${TRANSMISSION_IP}:${TRANSMISSION_PORT} -n ${TRANSMISSION_USER}:${TRANSMISSION_PASSWORD} -l"
local output local output
output=$(retry_command "$cmd" 3 20) output=$(retry_command "$real_cmd" 3 20)
# Log the raw output for debugging
log_info "Raw command output:"
log_info "$output"
# Extract IDs directly using awk # Extract IDs directly using awk
# Skip the header line (NR>1) and print the first column # Skip the header line (NR>1) and print the first column
# The IDs are right-aligned with spaces in front, so we need to trim them # The IDs are right-aligned with spaces in front, so we need to trim them
echo "$output" | awk 'NR>1 && NF>1 {gsub(/^[ ]+/, "", $1); if ($1 ~ /^[0-9]+$/) print $1}' local torrent_ids
torrent_ids=$(echo "$output" | awk 'NR>1 && NF>1 {gsub(/^[ ]+/, "", $1); if ($1 ~ /^[0-9]+$/) print $1}')
# Check if we found any torrents
if [[ -z "$torrent_ids" ]]; then
log_info "No torrent IDs found in transmission output"
else
log_info "Found torrent IDs: $torrent_ids"
fi
echo "$torrent_ids"
} }
# get_torrent_info: Gets detailed info for a specific torrent # get_torrent_info: Gets detailed info for a specific torrent