Skip to content

get_ports_from_caddy_config crashes on empty or unexpected Caddy admin config #225

Open

Description

@Vrittigyl

Describe the bug

get_ports_from_caddy_config crashes when the Caddy admin API returns a fresh or empty configuration (null or {}). The function assumes a fully populated HTTP config and directly indexes nested keys, leading to runtime errors.

To Reproduce

  • Start Caddy with no routes loaded (fresh instance).

  • Ensure GET /config/ returns null or {}.

  • Run:
    python3 -m autodeploy.autodeploy config.json

  • The script crashes while parsing the Caddy config.

Expected behaviour

If no active Caddy HTTP routes exist, the function should return an empty dictionary so the deployment logic can fall back to the default behaviour (use today’s date).

Additional context

Issues in the current implementation:

  • Does not handle null or empty JSON responses from the Caddy admin API.

  • Assumes a fixed Caddy config structure: apps → http → servers → srv0 → routes.

  • Crashes if srv0 does not exist or if multiple servers are defined.

  • Returns early if a single route lacks a match field, even if other valid routes exist.

  • Uses deeply nested indexing without guarding against missing keys or empty lists.

  • Assumes upstream dial is always in host:port format.

These issues prevent the script from running on a fresh Caddy setup and make it fragile to config changes.

Activity

  1. m-appel commented on Feb 2, 2026

    @m-appel
    Member

    Although this code is not actively used currently, you can fix this if you want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions