Better error message when multiple images are found.

This commit is contained in:
Sam Rose 2024-04-03 11:40:14 +01:00
parent 8cffdeda56
commit 258226ddef
No known key found for this signature in database
1 changed files with 5 additions and 1 deletions

View File

@ -44,7 +44,11 @@ function getTestcontainers(): ContainerInfo[] {
export function getContainerByImage(image: string) {
const containers = getTestcontainers().filter(x => x.Image.startsWith(image))
if (containers.length > 1) {
throw new Error(`Multiple containers found with image: ${image}`)
let errorMessage = `Multiple containers found starting with image: "${image}"\n\n`
for (const container of containers) {
errorMessage += JSON.stringify(container, null, 2)
}
throw new Error(errorMessage)
}
return containers[0]
}