amir20/dozzle · error

failed to fetch logs

Error message

failed to fetch logs: %w

What it means

The call to cs.LogsBetweenDates(...) (via the container ClientService) failed before any streaming began, so the error is wrapped as 'failed to fetch logs'. It indicates a problem reaching the container or its host, not with argument validation.

Solutions

  1. Re-resolve the container id with find_containers to confirm it still exists
  2. Check the Docker daemon / agent connectivity for the target host
  3. Retry; transient daemon or network failures often clear on a second call
  4. Inspect host errors logged via logHostErrors for the root cause

Example fix

// before
logs = fetchContainerLogs({container_id: staleId})
// after
const found = await findContainers({name: "myapp"})
if (found.length) logs = await fetchContainerLogs({container_id: found[0].id})
Defensive patterns

Strategy: try-catch

Validate before calling

const cs = await findContainers({}); if (!cs.some(c => c.id === containerId)) throw new Error('container not found: ' + containerId);

Type guard

null

Try / catch

try { logs = await fetchContainerLogs({container_id: id}) } catch (e) { if (/failed to fetch logs/.test(e.message)) { await sleep(1000); logs = await fetchContainerLogs({container_id: id}); } else throw e; }

Prevention

When it happens

Trigger: Container does not exist on the host; Docker daemon unreachable; the container is stopped and the driver cannot open its log file; context deadline/cancellation fires during the call.

Common situations: Container was removed or restarted between resolve and log fetch; remote agent host offline; Docker socket permissions/daemon down; k8s pod deleted.

Understand the failure class

Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.

Related errors


AI-assisted analysis of amir20/dozzle@d9463cbe21 (2026-09-07). Data as JSON: /api/errors/e55b86e73a34aaed. Report an issue: GitHub.

Appendix: source

Thrown at internal/cloud/tools_logs.go:71

		}
		end = t
	}

	var re *regexp.Regexp
	if args.Regex != "" {
		var err error
		re, err = regexp.Compile(args.Regex)
		if err != nil {
			return nil, fmt.Errorf("invalid regex pattern: %w", err)
		}
	}

	ctx, cancel := context.WithCancel(ctx)
	defer cancel()

	logCh, err := cs.LogsBetweenDates(ctx, start, end, container.STDOUT|container.STDERR)
	if err != nil {
		return nil, fmt.Errorf("failed to fetch logs: %w", err)
	}

	const maxLines = 100
	entries := make([]*pb.LogEntry, 0, maxLines)
	for event := range logCh {
		msg, matches := matchesFilters(event, &args, re)
		if !matches {
			continue
		}

		entries = append(entries, &pb.LogEntry{
			Timestamp: event.Timestamp,
			Message:   msg,
			Stream:    event.Stream,
			Level:     event.Level,
		})

		if len(entries) >= maxLines {

View on GitHub (pinned to d9463cbe21)