{"record":{"id":"c8e146917d4a7349","repo":"amir20/dozzle","slug":"error-finding-container-s-v","errorCode":null,"errorMessage":"error finding container %s: %v","messagePattern":"error finding container (.+?): (.+?)","errorType":"http","errorClass":null,"httpStatus":400,"severity":"error","filePath":"internal/web/download.go","lineNumber":104,"sourceCode":"\t\tid               string\n\t\tcontainerService *container_support.ContainerService\n\t}\n\tcontainers := make([]containerInfo, 0, len(hostIds))\n\n\tfor _, hostId := range hostIds {\n\t\tparts := strings.Split(hostId, \"~\")\n\t\tif len(parts) != 2 {\n\t\t\tlog.Error().Msgf(\"invalid host id: %s\", hostId)\n\t\t\thttp.Error(w, fmt.Sprintf(\"invalid host id: %s\", hostId), http.StatusBadRequest)\n\t\t\treturn\n\t\t}\n\n\t\thost := parts[0]\n\t\tid := parts[1]\n\t\tcontainerService, err := h.hostService.FindContainer(host, id, userLabels)\n\t\tif err != nil {\n\t\t\tlog.Error().Err(err).Msgf(\"error finding container %s\", id)\n\t\t\thttp.Error(w, fmt.Sprintf(\"error finding container %s: %v\", id, err), http.StatusBadRequest)\n\t\t\treturn\n\t\t}\n\n\t\tcontainers = append(containers, containerInfo{\n\t\t\thostId:           hostId,\n\t\t\thost:             host,\n\t\t\tid:               id,\n\t\t\tcontainerService: containerService,\n\t\t})\n\t}\n\n\t// Determine zip filename from optional name param or default\n\tzipName := \"container-logs\"\n\tif name := r.URL.Query().Get(\"name\"); name != \"\" {\n\t\t// Sanitize: keep only alphanumeric, hyphens, underscores, dots\n\t\tsanitized := strings.Map(func(r rune) rune {\n\t\t\tif (r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') || (r >= '0' && r <= '9') || r == '-' || r == '_' || r == '.' {\n\t\t\t\treturn r","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/amir20/dozzle/blob/d9463cbe21874e44ab79db6fa63e746ca7d22928/internal/web/download.go#L86-L122","documentation":"After the host~id split succeeds, downloadLogs calls hostService.FindContainer(host, id, userLabels). If the host cannot be reached or no container with that id exists on it, a 400 containing \"error finding container %s: %v\" is returned with the underlying error appended.","triggerScenarios":"GET download with host~id where the host is unknown/disconnected or the container id does not exist (e.g. container was recreated and its id changed).","commonSituations":"Container recreated after image upgrade so the stored id is stale; agent host offline or removed from the host list; typos in host names when crafting URLs by hand; k8s pod restarts producing new ids.","solutions":["Refresh the container list and use the current container id from the API.","Verify the host segment matches an available host id/name.","Check host connectivity (remote agent reachable) before retrying."],"exampleFix":"// before\nconst stale = JSON.parse(localStorage.getItem('lastContainer'))\ndownload(stale.host + '~' + stale.id)\n// after\nconst containers = await fetch('/api/containers.json').then(r => r.json())\nconst current = containers.find(c => c.name === stale.name)\nif (current) download(current.host + '~' + current.id)","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const res = await fetch(url);\n  if (res.status === 400) {\n    const msg = await res.text();\n    if (msg.startsWith('error finding container')) await refreshContainersAndRetry();\n  }\n} catch (e) { /* network failure */ }","preventionTips":["Refresh container ids after any container recreate/upgrade.","Confirm host connectivity before querying per-container endpoints.","Don't persist raw host~id across sessions; re-resolve by name."],"tags":["http","docker","resource-not-found"],"backgroundTag":"record-not-found","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"}