{"record":{"id":"9c33c808ddb531b8","repo":"portainer/portainer","slug":"unable-to-retrieve-stacks-w","errorCode":null,"errorMessage":"Unable to retrieve stacks: %w","messagePattern":"Unable to retrieve stacks: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"api/http/handler/docker/utils/get_stacks.go","lineNumber":29,"sourceCode":"\t\"github.com/portainer/portainer/api/http/security\"\n\t\"github.com/portainer/portainer/api/uac\"\n)\n\ntype StackViewModel struct {\n\tInternalStack *portainer.Stack\n\n\tID         portainer.StackID\n\tName       string\n\tIsExternal bool\n\tType       portainer.StackType\n\tLabels     map[string]string\n}\n\n// GetDockerStacks retrieves all the stacks associated to a specific environment filtered by the user's access.\nfunc GetDockerStacks(tx dataservices.DataStoreTx, securityContext *security.RestrictedRequestContext, environmentID portainer.EndpointID, containers []types.Container, services []swarm.Service) ([]StackViewModel, error) {\n\tstacks, err := tx.Stack().ReadAll()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"Unable to retrieve stacks: %w\", err)\n\t}\n\n\tuser, err := tx.User().Read(securityContext.UserID)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"Unable to retrieve user: %w\", err)\n\t}\n\n\tstacksNameSet := map[string]*StackViewModel{}\n\n\tfor i := range stacks {\n\t\tstack := stacks[i]\n\t\tif stack.EndpointID == environmentID {\n\t\t\tstacksNameSet[stack.Name] = &StackViewModel{\n\t\t\t\tInternalStack: &stack,\n\t\t\t\tID:            stack.ID,\n\t\t\t\tName:          stack.Name,\n\t\t\t\tIsExternal:    false,\n\t\t\t\tType:          stack.Type,","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/portainer/portainer/blob/17e74456ff6e794b9d5439ec3fa06922aa18a3f8/api/http/handler/docker/utils/get_stacks.go#L11-L47","documentation":"Error \"Unable to retrieve stacks: %w\" thrown in portainer/portainer.","triggerScenarios":"Thrown at api/http/handler/docker/utils/get_stacks.go:29 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"17e74456ff6e794b9d5439ec3fa06922aa18a3f8","analyzedAt":"2026-08-26T23:09:01.915Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}