Skip to content

Normalize Caddy.Admin.Api to {:ok, _}/{:error, _} contracts (currently swallows errors) #10

Description

@gsmlg

Problem

Caddy.Admin.Api has inconsistent return contracts and silently swallows errors:

  • get/1, load/1, stop/0 return %{status: 0, body: nil} on failure
  • get_config/0,1, post_config, put_config, patch_config, delete_config return nil on failure
  • adapt/1 returns %{} on failure
  • health_check/0, get_metrics/1, server_info/0 return proper {:ok, _}/{:error, _} tuples

Callers are forced into fragile checks, e.g. map_size(json_config) > 0 in lib/caddy/server/external.ex:399.

Additional issues in the same module

  • load/1 with a map does a shallow Map.merge with the current config (lib/caddy/admin/api.ex:89) — surprising semantics that silently clobber nested keys
  • def api, do: nil (lib/caddy/admin/api.ex:51) is a dead placeholder holding a moduledoc
  • ~400 lines of copy-pasted telemetry timing boilerplate — a single private instrument/3 helper would cut the module by two-thirds

Proposal

Converge every function on tagged tuples. This is a breaking change — batch for a 3.0 release.

Activity

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

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions