{"record":{"id":"9f04775b8e04f3e9","repo":"docker/compose","slug":"already-exists","errorCode":null,"errorMessage":"already exists","messagePattern":"already exists","errorType":"error_code","errorClass":"ErrAlreadyExists","httpStatus":null,"severity":"error","filePath":"pkg/api/errors.go","lineNumber":33,"sourceCode":"*/\n\npackage api\n\nimport (\n\t\"errors\"\n)\n\nconst (\n\t// ExitCodeLoginRequired exit code when command cannot execute because it requires cloud login\n\t// This will be used by VSCode to detect when creating context if the user needs to login first\n\tExitCodeLoginRequired = 5\n)\n\nvar (\n\t// ErrNotFound is returned when an object is not found\n\tErrNotFound = errors.New(\"not found\")\n\t// ErrAlreadyExists is returned when an object already exists\n\tErrAlreadyExists = errors.New(\"already exists\")\n\t// ErrForbidden is returned when an operation is not permitted\n\tErrForbidden = errors.New(\"forbidden\")\n\t// ErrUnknown is returned when the error type is unmapped\n\tErrUnknown = errors.New(\"unknown\")\n\t// ErrNotImplemented is returned when a backend doesn't implement an action\n\tErrNotImplemented = errors.New(\"not implemented\")\n\t// ErrUnsupportedFlag is returned when a backend doesn't support a flag\n\tErrUnsupportedFlag = errors.New(\"unsupported flag\")\n\t// ErrCanceled is returned when the command was canceled by user\n\tErrCanceled = errors.New(\"canceled\")\n\t// ErrParsingFailed is returned when a string cannot be parsed\n\tErrParsingFailed = errors.New(\"parsing failed\")\n\t// ErrNoResources is returned when operation didn't selected any resource\n\tErrNoResources = errors.New(\"no resources\")\n)\n\n// IsNotFoundError returns true if the unwrapped error is ErrNotFound\nfunc IsNotFoundError(err error) bool {","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/docker/compose/blob/ddc4b044b62e9f715212ea4143fa830fac76382f/pkg/api/errors.go#L15-L51","documentation":"api.ErrAlreadyExists is the canonical sentinel for attempting to create an object that already exists (for example creating a resource with the same name twice). Like the other api sentinels it is meant to be detected with errors.Is or api.IsAlreadyExistsError, letting callers distinguish conflicts from other failures.","triggerScenarios":"Programmatic calls into pkg/api that create a named resource which is already present; backends wrap engine conflict responses into this sentinel so the CLI layer can react (e.g. skip creation or surface a clear message).","commonSituations":"Re-running a provisioning flow without cleanup; concurrent processes creating the same compose resource; scripts that assume idempotent create semantics.","solutions":["Check for the object's existence before creating it, or treat IsAlreadyExistsError as success when idempotency is desired.","Remove/rename the existing object if a fresh create is required.","Serialize concurrent creation steps (lock or ordering) so only one creator runs."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"docker compose ls --format json | jq -e --arg p \"$PROJECT\" 'map(.Name) | index($p)' >/dev/null || echo \"project $PROJECT already absent\" ","typeGuard":"func isAlreadyExists(err error) bool { return api.IsAlreadyExistsError(err) }","tryCatchPattern":"err := createResource(...)\nif err != nil {\n    if api.IsAlreadyExistsError(err) {\n        err = nil // idempotent success\n    }\n}","preventionTips":["Make creation flows idempotent by tolerating IsAlreadyExistsError.","Clean up resources between re-runs of provisioning scripts."],"tags":["api","sentinel-error","conflict"],"backgroundTag":null,"analyzedSha":"ddc4b044b62e9f715212ea4143fa830fac76382f","analyzedAt":"2026-08-15T13:31:42.319Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}