fix: handle null ports in Docker container table (#5313)
When Docker API returns `null` for container ports (instead of `[]`), the Docker management page crashes. Added optional chaining on `ports?.length` to handle this case. Fixes #5311 Co-authored-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
This commit is contained in:
1 parent
d53c922688
commit
1639da5779
4 files changed
+5
-3
No files matched your search
@@ -76,6 +76,7 @@ const createColumns = (
|
||||
accessorKey: "ports",
|
||||
header: t("docker.field.ports.label"),
|
||||
Cell({ cell }) {
|
||||
if (!cell.row.original.ports) return null;
|
||||
if (!cell.row.original.ports.length) return null;
|
||||
return (
|
||||
<OverflowBadge overflowCount={1} data={cell.row.original.ports.map((port) => port.PrivatePort.toString())} />
|
||||
|
||||
@@ -140,7 +140,7 @@ interface DockerContainer {
|
||||
id: string;
|
||||
state: ContainerState;
|
||||
image: string;
|
||||
ports: Port[];
|
||||
ports: Port[] | undefined;
|
||||
iconUrl: string | null;
|
||||
cpuUsage: number;
|
||||
memoryUsage: number;
|
||||
|
||||
@@ -21,7 +21,7 @@ export const AddDockerAppToHomarrModal = createModal<AddDockerAppToHomarrProps>(
|
||||
{
|
||||
initialValues: {
|
||||
containerUrls: innerProps.selectedContainers.map((container) => {
|
||||
if (container.ports[0]) {
|
||||
if (Array.isArray(container.ports) && container.ports[0]) {
|
||||
return `http://${container.ports[0].IP}:${container.ports[0].PublicPort}`;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import dayjs from "dayjs";
|
||||
import type { ContainerInfo, ContainerStats } from "dockerode";
|
||||
import type Dockerode from "dockerode";
|
||||
|
||||
import { db, like, or } from "@homarr/db";
|
||||
import { icons } from "@homarr/db/schema";
|
||||
@@ -72,7 +73,7 @@ async function getContainersWithStatsAsync() {
|
||||
cpuUsage,
|
||||
memoryUsage,
|
||||
image: container.Image,
|
||||
ports: container.Ports,
|
||||
ports: container.Ports as Dockerode.Port[] | undefined,
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user