{"record":{"id":"6caa844e40bdcd10","repo":"portainer/portainer","slug":"failed-to-create-source-for-custom-template-d-w","errorCode":null,"errorMessage":"failed to create source for custom template %d: %w","messagePattern":"failed to create source for custom template (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"api/datastore/migrator/migrate_2_43_0.go","lineNumber":295,"sourceCode":"\t\t\t\t\treturn m.teamMembershipService.Tx(tx).TeamMembershipsByUserID(userId)\n\t\t\t\t},\n\t\t\t)\n\n\t\t\tsrcID, exists := sourcesByKey[key]\n\n\t\t\tif !exists {\n\t\t\t\tsrc := &portainer.Source{\n\t\t\t\t\tName:               gittypes.RepoName(cfg.URL),\n\t\t\t\t\tType:               portainer.SourceTypeGit,\n\t\t\t\t\tGit:                cfg,\n\t\t\t\t\tOwnerID:            ownerId,\n\t\t\t\t\tPublic:             public,\n\t\t\t\t\tAdministratorsOnly: adminOnly,\n\t\t\t\t\tUserAccesses:       users,\n\t\t\t\t\tTeamAccesses:       teams,\n\t\t\t\t}\n\t\t\t\tif err := m.sourceService.Tx(tx).Create(adminUserContext, src); err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"failed to create source for custom template %d: %w\", t.ID, err)\n\t\t\t\t}\n\t\t\t\tsrcID = src.ID\n\t\t\t\tnewSrcID = src.ID\n\t\t\t} else {\n\t\t\t\tsrc, err := m.sourceService.Tx(tx).Read(adminUserContext, srcID)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"failed to read source %d for custom template %d: %w\", srcID, t.ID, err)\n\t\t\t\t}\n\n\t\t\t\tApplyUACOnSourceUpdate_2_43_0(src, users, teams, public, adminOnly, ownerId)\n\n\t\t\t\tif err := m.sourceService.Tx(tx).Update(adminUserContext, srcID, src); err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"failed to update source %d for custom template %d: %w\", srcID, t.ID, err)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tt.Artifact = &portainer.Artifact{\n\t\t\t\tFiles: []portainer.ArtifactFile{{","sourceCodeStart":277,"sourceCodeEnd":313,"githubUrl":"https://github.com/portainer/portainer/blob/17e74456ff6e794b9d5439ec3fa06922aa18a3f8/api/datastore/migrator/migrate_2_43_0.go#L277-L313","documentation":"Error \"failed to create source for custom template %d: %w\" thrown in portainer/portainer.","triggerScenarios":"Thrown at api/datastore/migrator/migrate_2_43_0.go:295 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"}