{"record":{"id":"e55b86e73a34aaed","repo":"amir20/dozzle","slug":"failed-to-fetch-logs-w","errorCode":null,"errorMessage":"failed to fetch logs: %w","messagePattern":"failed to fetch logs: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cloud/tools_logs.go","lineNumber":71,"sourceCode":"\t\t}\n\t\tend = t\n\t}\n\n\tvar re *regexp.Regexp\n\tif args.Regex != \"\" {\n\t\tvar err error\n\t\tre, err = regexp.Compile(args.Regex)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"invalid regex pattern: %w\", err)\n\t\t}\n\t}\n\n\tctx, cancel := context.WithCancel(ctx)\n\tdefer cancel()\n\n\tlogCh, err := cs.LogsBetweenDates(ctx, start, end, container.STDOUT|container.STDERR)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to fetch logs: %w\", err)\n\t}\n\n\tconst maxLines = 100\n\tentries := make([]*pb.LogEntry, 0, maxLines)\n\tfor event := range logCh {\n\t\tmsg, matches := matchesFilters(event, &args, re)\n\t\tif !matches {\n\t\t\tcontinue\n\t\t}\n\n\t\tentries = append(entries, &pb.LogEntry{\n\t\t\tTimestamp: event.Timestamp,\n\t\t\tMessage:   msg,\n\t\t\tStream:    event.Stream,\n\t\t\tLevel:     event.Level,\n\t\t})\n\n\t\tif len(entries) >= maxLines {","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/amir20/dozzle/blob/d9463cbe21874e44ab79db6fa63e746ca7d22928/internal/cloud/tools_logs.go#L53-L89","documentation":"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.","triggerScenarios":"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.","commonSituations":"Container was removed or restarted between resolve and log fetch; remote agent host offline; Docker socket permissions/daemon down; k8s pod deleted.","solutions":["Re-resolve the container id with find_containers to confirm it still exists","Check the Docker daemon / agent connectivity for the target host","Retry; transient daemon or network failures often clear on a second call","Inspect host errors logged via logHostErrors for the root cause"],"exampleFix":"// before\nlogs = fetchContainerLogs({container_id: staleId})\n// after\nconst found = await findContainers({name: \"myapp\"})\nif (found.length) logs = await fetchContainerLogs({container_id: found[0].id})","handlingStrategy":"try-catch","validationCode":"const cs = await findContainers({}); if (!cs.some(c => c.id === containerId)) throw new Error('container not found: ' + containerId);","typeGuard":"null","tryCatchPattern":"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; }","preventionTips":["Re-resolve container ids shortly before use","Check host connectivity for remote agents","Treat this error as possibly transient and retry once"],"tags":["cloud-tools","docker","log-streaming"],"backgroundTag":"api-request-failed","analyzedSha":"d9463cbe21874e44ab79db6fa63e746ca7d22928","analyzedAt":"2026-09-07T10:08:55.855Z","contentChangedAt":"2026-09-07T10:08:55.855Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}