Files
unshackle/docs/guide/troubleshooting.md
T

25 KiB

Troubleshooting & Debugging

When a download fails, a service misbehaves, or unshackle cannot get a content key, unshackle gives you three tools to find out why:

  • Debug logging: verbose DEBUG-level console output plus a structured, machine-readable log file.
  • unshackle env: make sure that unshackle finds the external tools it depends on, and see exactly which directories and config file are in use.
  • Targeted toggles: debug_keys and debug_requests for the two areas (DRM keys and raw HTTP traffic) that are deliberately quiet by default.

The sections below cover how to enable each of them, how to read what they give, and which diagnostic fits which failure mode.


Turning on debug logging

There are two independent ways to enable debug logging, and they do slightly different things.

=== "The -d / --debug flag"

The root-level flag turns on verbose logging for a single invocation:

```console
unshackle -d dl SERVICE TITLE_ID
```

It must come **before** the subcommand, because it is an option on the root `unshackle` command, not on `dl`.

`-d` does three things:

1. Sets the console log level to `DEBUG`, so every module logs its full detail.
2. Enables the structured JSON debug log file (see [below](#the-structured-json-debug-log)).
3. Adds source-path annotations to console log lines (which file and line each message came from).

=== "The debug config key"

To make debug logging the default for every run without typing `-d` each time, set it in your `unshackle.yaml`:

```yaml
debug: true
```

or with the [`cfg`](cli-reference.md#cfg) command:

```console
unshackle cfg debug true
```

!!! note "`debug: true` is not identical to `-d`"
    The `debug` config key enables the **JSON debug log file**, but it does **not** raise the console to `DEBUG` level and does not add source-path annotations. Those only happen when you pass the `-d` flag. Use the flag when you want to *watch* the verbose output live. Use the config key when you want only the log file written every time. Passing `-d` is the most complete option, and you can combine both.

!!! warning "Debug logging can be noisy and revealing" Debug output is verbose and includes request metadata, service internals, and stack traces. unshackle automatically redacts secrets, URLs, and local paths (see Redaction), but you should still read a log before you share it publicly.


The structured JSON debug log

Beyond the console output, unshackle writes a structured log in JSON Lines format: one complete JSON object per line. You can filter, examine, and analyse this file with standard tooling (jq, grep, a text editor). It is safe to attach to a bug report, because unshackle redacts it, unless debug_requests is on (see Debugging HTTP traffic).

Where it is written

unshackle makes the debug log during a dl run, and during import, which wraps dl. The path is:

<logs directory>/unshackle_debug_<service>_<timestamp>.jsonl

For example, unshackle_debug_EXAMPLE_20260703-142530.jsonl. The <service> tag and the timestamp mean each download gets its own file, so runs never overwrite each other.

!!! tip "Find your logs directory" The logs directory defaults to a logs folder inside the package data directory, but you can move it with the directories.logs config key. To see the exact resolved path on your machine, use unshackle env info and read the Directories table.

What a log entry looks like

Every line is a self-contained JSON object. The first line of each log file records the environment:

{"timestamp":"2026-07-03T14:25:30.123456+00:00","session_id":"a1b2c3d4","level":"INFO","operation":"session_start","message":"Debug logging session started","context":{"unshackle_version":"5.3.0","unshackle_code_hash":"1d22a1e","python_version":"3.12.4 ...","platform":"Linux-6.18.5-x86_64","platform_system":"Linux","platform_release":"6.18.5"}}

Quote unshackle_code_hash in a bug report. It fingerprints the framework source you operate, so it tells us the exact code state even when you did not install from git. A hash that matches no release means that someone edited the source locally.

Subsequent lines record the operations: service calls, DRM licence requests, vault lookups, downloader progress, and errors. Common fields include:

Field Meaning
timestamp UTC ISO-8601 time of the entry.
session_id Short random ID shared by every entry in one run, handy for correlating lines.
level DEBUG, INFO, WARNING, or ERROR.
operation The action being logged, e.g. service_call, download_init, drm_get_widevine_license, vault_get_key, session_end.
message Human-readable description (redacted).
service Service tag the entry belongs to, when applicable.
context Arbitrary structured detail for the operation.
request / response HTTP method/URL and response metadata for network operations.
duration_ms How long a timed operation took.
success Whether the operation succeeded.
error On failures: the exception type, message, and a full traceback array (all redacted).

Reading and filtering the log

Because each line is independent JSON, jq is the natural tool:

# Show only error-level entries
jq 'select(.level == "ERROR")' unshackle_debug_EXAMPLE_20260703-142530.jsonl

# List every operation and whether it succeeded
jq -c '{operation, success}' unshackle_debug_EXAMPLE_20260703-142530.jsonl

# Pull the traceback out of the first error
jq -r 'select(.error) | .error.traceback[]' unshackle_debug_EXAMPLE_20260703-142530.jsonl

# Show only DRM / licensing operations
jq 'select(.operation | startswith("drm_"))' unshackle_debug_EXAMPLE_20260703-142530.jsonl

unshackle logs the binary-tool versions (shaka-packager, mp4decrypt, mkvmerge, FFmpeg, FFprobe) near the start of a dl run. Often that is the fastest way to make sure that a muxing or decryption failure is really a wrong-version problem.


Debugging DRM keys with debug_keys

By default, unshackle redacts the content keys in the JSON debug log. It writes any field that looks like a content key as [REDACTED]. This keeps logs shareable. When you specifically debug a key-retrieval or decryption problem and need to see the actual KID/KEY values unshackle fetched, enable debug_keys:

debug_keys: true
unshackle cfg debug_keys true

With debug_keys: true, the debug log stops masking content key fields. You can then see which content keys came back from a licence server or vault, and compare them against what decryption expected.

!!! warning "Keys are sensitive, turn this back off" debug_keys writes real content keys into the log file in cleartext. Only enable it while you diagnose a content key problem. Never share a log written with it on, and set it back to false when you are done. Note that debug_keys only affects the JSON debug log file. It does not change what the console prints.

Fields that are always redacted regardless of debug_keys (anything whose name contains password, token, secret, auth, or cookie) stay masked, so credentials never leak even in a keys-on log. The http_request entries of debug_requests are the exception.


Debugging HTTP traffic with debug_requests

debug_requests does two things: it keeps the HTTP library logs in the console, and it writes a record of each HTTP request to the JSON debug log.

HTTP library logs in the console

When you pass -d, unshackle raises its own modules to DEBUG but deliberately silences the noisy low-level HTTP libraries (urllib3, requests, rnet, httpx, httpcore, hpack, h2) back down to WARNING. Without this, a single download would bury the useful output under thousands of connection-pool and HTTP/2 frame messages.

Sometimes a request fails at the TLS or connection layer, and you need the underlying library's own logs. If you need that low-level traffic, enable debug_requests:

debug_requests: true
unshackle cfg debug_requests true

With debug_requests: true, unshackle leaves those libraries at DEBUG level when you operate it with -d, so their request/response chatter appears in the console.

!!! note "The console logs need -d" Without -d (verbose console logging), unshackle shows no HTTP library logs. Combine them: unshackle -d dl ... with debug_requests: true in config.

Request records in the JSON debug log

debug_requests is the one switch that writes request records to the JSON debug log. With debug_requests: true and the JSON debug log on (-d or debug: true), unshackle writes one http_request entry for each HTTP attempt. With debug_requests: false, the default, a -d run writes no http_request entry. A request that unshackle retries gives one entry for each attempt. A redirect gives one entry for each hop.

Field Content
request.method The HTTP method.
request.host The host name and port, with no scheme and no user name or password.
request.path The URL path, as sent.
request.query The query string, as sent.
request.attempt The attempt number, from 1.
request.body The body of a JSON, form, XML or text/* request, as sent. A JSON body is an object. A binary body is not recorded.
response.status The HTTP status, or null when no response came back.
response.size The Content-Length of the response. When the server sent none, the length of the recorded body, else null.
response.body The text response body, as received. A JSON body is a JSON object, so jq can query it. Other text is a string.
response.body_size The full size of the decoded body in bytes, when unshackle cut it to debug_requests_body_limit. response.size is the size on the wire, which can be compressed.
response.body_error The failure, when unshackle could not read the body.
response.body_cut true when unshackle cut the body. A cut JSON body is a string.
duration_ms The time from the start of the attempt to the response headers.
failure The failure, without the URL, for an attempt that raised.

unshackle records the body of a JSON, XML or text/* response. It records no body for a manifest (MPD, M3U8 or ISM, by its content type, or by the suffix of the request path when the response is not JSON), a binary content type, an event stream, a request sent with stream=True, or a server process. A request body is recorded by the same rule, by the request Content-Type; a form body counts as text. The entries contain no headers. Core writes no entry for the media requests that it makes. These are the segment and range-probe requests of a track download, and the init segment, index and probe reads before it. A range read that service code makes still writes an entry. Playlist and manifest fetches write an entry.

jq 'select(.operation == "http_request") | [.request.method, .request.host, .request.path, .response.status]' \
  unshackle_debug_EXAMPLE_20260703-142530.jsonl
jq 'select(.operation == "http_request" and .request.path == "/v1/titles") | .response.body' \
  unshackle_debug_EXAMPLE_20260703-142530.jsonl

The record covers the HTTP sessions that unshackle builds: the session from the service's get_session(), the import and --remote sessions, and the sessions of core helpers. A separate requests.Session that service code makes itself writes no entry.

On a serve server, the entries for the requests of a service stay on the server, with no body. A download job whose dl run has the JSON debug log on writes them to that log. A remote session writes none, because serve opens no JSON debug log for it. unshackle never sends them to a remote client: not in the remote session log, the remote session channel, an API reply or an error. A remote client with its own debug_requests: true records its own requests to the server, with the response bodies, in its own JSON debug log.

On an HTTP session of the requests library, urllib3 retries inside one send. The attempts before the last then have no duration_ms and no response.size. A request that fails after all its retries gives one entry for the last failure, with request.attempt set to null.

!!! danger "A request record holds secrets" unshackle writes the http_request entries as received. It masks only the local folder prefixes (redact_paths). With debug_requests on, the JSONL file holds tokens, passwords, cookies, content keys and account data, in the path, the query and the body. debug_keys does not apply to these entries. Keep the file on your computer. Never attach it to a report.


What gets redacted

unshackle redacts logged strings so that debug output is safe to share. It applies three passes to every logged message, error, and structured value:

  • Secrets: unshackle replaces passwords, tokens, API secrets, auth values, and cookies with [REDACTED].
  • URLs: unshackle collapses every http(s) URL to redacted. It keeps only the file extension, so a manifest still shows as redacted.mpd and a segment as redacted.m4s. This hides the CDN, manifest, segment, and licence-server locations, but keeps the type of resource.
  • Local paths: unshackle replaces install-root, virtualenv, and home-directory prefixes with tokens, so your username and machine layout do not appear in logs.

The http_request entries of debug_requests get only the local path pass. Their secrets, URLs and bodies stay as received.

The redact_paths config key controls path redaction, and it is on by default:

redact_paths: true   # default - mask local base directories in logged paths

Set redact_paths: false if you debug a path problem locally and want to see full, unmasked paths in the console and logs. unshackle always applies secret and URL redaction in the JSON debug log, except in the http_request entries, and this toggle does not change that.


Checking your environment

Many "download failed" problems are really missing external tools or a config file that is not where you think it is. The unshackle env command group answers both questions before you dig into logs.

env check

unshackle env check verifies every external binary unshackle can use and prints a table of what's installed:

unshackle env check

It reports each tool's status (✓ installed / ✗ missing), whether it is required or optional, and what it is for. A summary line tells you the installed-vs-total count and, if anything mandatory is absent, exactly which required tools are missing.

The required tools (unshackle will not get far without them) are:

Tool Purpose
FFmpeg Media processing
FFprobe Media analysis
MKVToolNix (mkvmerge) MKV muxing
mkvpropedit MKV metadata
shaka-packager DRM decryption

Optional tools unlock extra capabilities. For example, mp4decrypt (alternative decryptor), dovi_tool / HDR10Plus_tool (Dolby Vision / HDR10+), SubtitleEdit / CCExtractor (subtitle conversion and CC extraction), MPV / FFplay (playback preview), and git (service repositories) or docker (Gluetun VPN, see Proxies & VPN).

!!! tip "First thing to run when something breaks" If a decryption step errors, a mux fails, or a Dolby Vision title will not process, use unshackle env check first. A red ✗ next to the relevant tool is the answer far more often than a bug in unshackle.

env info

unshackle env info shows where unshackle reads configuration from and where every working directory lives:

unshackle env info
  • If unshackle found a config file, it prints the path it was loaded from. If it found none, it shows every location it would accept one (see Config file discovery below). You can then make the file in the right place.
  • It then prints a Directories table for every configured path: downloads, temp, cache, cookies, logs, exports, wvds, prds, the services search paths, and more.

This is the authoritative way to answer "where do my logs, downloads and cookies go?" The defaults are relative to the installed package. The table also shows any directories: overrides from your config.

env clear

Stale cache or leftover temp files can cause confusing behaviour (an old cached title list, a half-written temp file). env clear wipes those directories safely:

unshackle env clear cache            # clear the whole cache directory
unshackle env clear cache EXAMPLE    # clear just one service's cache subdirectory
unshackle env clear temp             # clear the temp working directory

Each command reports how many files it removed and how much space it freed, then recreates the empty directory.

!!! tip "Cache-related weirdness" If a service keeps returning stale titles or metadata even after the source changed, clear that service's cache with unshackle env clear cache <SERVICE>. See Vaults for the separate, persistent key-vault store, which env clear does not touch.


Common failure modes and how to inspect them

!!! example "A required tool is missing" Symptom: decryption, muxing, or analysis fails early, sometimes with a "binary not found" style error.

**Inspect:** use `unshackle env check` and look for a red `✗` on a **required** row. Run `unshackle setup` to install it, or install it by hand, and re-run.

!!! example "Decryption produces garbage or fails" Symptom: the download completes but the file will not play, or the decrypt step errors.

**Inspect:** enable `debug_keys` and operate unshackle with `-d`. Then examine the JSON debug log's `drm_*` and `vault_*` operations to see which content keys unshackle fetched, and from where. Also make sure that shaka-packager (or `mp4decrypt`) shows a sane version in the `download_init` binary-versions entry. See [DRM & CDM](drm-and-cdm.md).

!!! example "A vault served a wrong content key" Symptom: a warning names a content key and the vault it came from, either was bad, trying other vaults (the decode check failed) or is flagged bad, skipping (an earlier run flagged it). The download stops with The content key from the vault did not decrypt the track; run again, was bad and no other source has the key, or No vault or CDM produced a content key that decrypts the track when no source is left to try.

**Inspect:** while it decrypts a track whose content key came from a vault, unshackle keeps the ciphertext as a `.enc` sibling of the track file in the temp directory, and removes it afterwards; a leftover one is from a killed run and is safe to delete. Read the `bad_keys` table of your local SQLite vault to see which pairs are flagged and which vault each came from. See [Wrong keys from a poisoned vault](vaults.md#wrong-keys-from-a-poisoned-vault).

!!! example "A network request fails at the connection or TLS layer" Symptom: timeouts, connection resets, or handshake errors, and unshackle's own logs do not give the full cause.

**Inspect:** set `debug_requests: true` and operate unshackle with `-d` to show the underlying `urllib3` / `rnet` / `httpx` logs. In the JSON debug log, filter for `http_request` operations to see which request failed, with its status, attempt number and failure. If you use a proxy, also read [Proxies & VPN](proxies-and-vpn.md).

!!! example "A segment download fails after every retry" Symptom: the download stops with a line like MaxRetriesError: GET <host> failed: RequestError (stream closed because of a broken pipe), gave up after 5 failed attempts over 30s.

**Inspect:** the connection to the CDN host dropped on every attempt. This is almost always the network, the VPN, or the proxy, not the service. Run the download again: unshackle keeps the segments it already has. Over HTTP/2, all segments share one connection, so one drop fails every segment in flight. Set `network.http1_only: true` (see [Network & proxy](../reference/configuration/network.md)) to spread them over separate connections. Operate unshackle with `-d` to see each retry as a `segment_retry` entry in the JSON debug log.

!!! example "The wrong titles/metadata keep coming back" Symptom: a service returns outdated titles even after the source changed.

**Inspect:** the title cache is likely serving stale data. Clear it with `unshackle env clear cache <SERVICE>`, or bypass it for one run using the `dl` no-cache / reset-cache options (see [Downloading](downloading.md) and the [CLI Reference](cli-reference.md#dl)).

!!! example "A config value doesn't seem to apply" Symptom: a setting you edited has no effect.

**Inspect:** use `unshackle env info` to see **which** config file unshackle loaded, and `unshackle cfg --list` to dump the effective values. It is common to edit a config file in a location unshackle does not read from. See below.

Why is my config not being picked up?

unshackle loads the first unshackle.yaml it finds, in this order:

  1. unshackle.yaml inside the package's namespace directory.
  2. unshackle.yaml in the parent of that directory.
  3. unshackle.yaml in your OS user-config directory: on Linux ~/.config/unshackle/unshackle.yaml, on Windows %LOCALAPPDATA%\unshackle\unshackle.yaml, on macOS ~/Library/Application Support/unshackle/unshackle.yaml.

If you have config in more than one of these, an earlier one wins and unshackle silently ignores your edits to a later file. unshackle env info prints the path it loaded (or, if none exists, shows all three candidate locations so you can make the file correctly). See Configuration for editing values with the cfg command.


!!! note "Developer note: structured logging in code" Service and command code sends entries through the shared log_event(...) helper (and the timed_operation(...) context manager for timing a block) from unshackle.core.utilities. These are no-ops when you disable debug logging, so they are always safe to leave in place. When you add a new feature, call log_event("my_feature_event", message="...", context={...}). Do not write the "is the logger enabled?" guard again. unshackle does the redaction and the JSON-serialisation for you, and redacts any field whose name looks like a content key, a secret, or a token. Content keys only appear when the run has debug_keys enabled.

Logging conventions when adding entries

The debug log is tuned for developers troubleshooting pipeline flow (maximum signal, minimum noise), not for end users. A few conventions keep it that way. The log_event signature does not enforce them, so they are easy to miss and worth stating explicitly.

!!! tip "Log levels are a flow skeleton, not just severity" Treat level as structure, not decoration. Send exactly one INFO milestone per pipeline stage so that jq 'select(.level=="INFO")' reads back the whole end-to-end flow of a run. Everything internal goes to DEBUG. Failures go to ERROR. A sparse INFO is the whole point. It is the line a developer skims first to see where a run got to before it broke.

```console
# Read the pipeline's high-level flow, one line per stage
jq 'select(.level == "INFO")' unshackle_debug_EXAMPLE_20260703-142530.jsonl
```

!!! warning "No request bodies and no raw dumps" A log_event entry never holds a request body or a raw dump: no full Tracks object, no MPD/manifest body and no response payload. Only debug_requests records request and response bodies, in its http_request entries. Log only counts, ids, sizes, and safe_display_url(url). This keeps the log low-noise and prevents leaking title or manifest data into the file before redaction even runs. Redaction is a backstop, not a licence to dump raw objects.

!!! note "Operation names: <area>_<event>, no registry" Operation names are plain lowercase strings that follow an <area>_<event> convention: manifest_dash_parse, drm_decrypt, vault_get_key, tool_run. We write them inline at each call site on purpose. There is no central registry or enum. Do not look for one, and do not make one. The absence is a deliberate design choice, not an omission.

!!! note "Message reads alone; data lives in fields" Give every entry a single-sentence message that stands on its own. Put all structured data (context, counts, ids, duration_ms) in fields, not in the prose. This separation lets the log be both human-scannable and machine-filterable. A message like "Parsed DASH manifest" with context={"video": 4, "audio": 2} beats "Parsed manifest with 4 video and 2 audio tracks".

!!! tip "Let tool runs log themselves" For external-tool calls (FFmpeg, mkvmerge, dovi_tool, and friends), route through run_step / ffprobe, which auto-emit a tool_run entry capturing the binary's version, return code, and duration consistently. Only fall back to calling log_tool_run manually for a direct subprocess.run you genuinely cannot route through run_step. Auto-logging is the preferred path precisely because it captures those fields the same way every time.