{"record":{"id":"bd0de10be4dc07a7","repo":"plandex-ai/plandex","slug":"error-creating-custom-model-w","errorCode":null,"errorMessage":"error creating custom model: %w","messagePattern":"error creating custom model: %w","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"app/server/handlers/models.go","lineNumber":293,"sourceCode":"\t}\n\n\tfor _, modelPack := range customModelPacks {\n\t\tif _, exists := inputModelPackNames[modelPack.Name]; !exists {\n\t\t\ttoDeleteModelPackIds = append(toDeleteModelPackIds, modelPack.Id)\n\t\t}\n\t}\n\n\tnumChanges := len(toUpsertCustomModels) + len(toUpsertCustomProviders) + len(toUpsertModelPacks) + len(toDeleteCustomModelIds) + len(toDeleteCustomProviderIds) + len(toDeleteModelPackIds)\n\tif numChanges == 0 {\n\t\tw.WriteHeader(http.StatusOK)\n\t\tlog.Println(\"No changes to custom models/providers/model packs\")\n\t\treturn\n\t}\n\n\terr = db.WithTx(r.Context(), \"create custom models/providers/model packs\", func(tx *sqlx.Tx) error {\n\t\tfor _, model := range toUpsertCustomModels {\n\t\t\tif err := db.UpsertCustomModel(tx, model); err != nil {\n\t\t\t\treturn fmt.Errorf(\"error creating custom model: %w\", err)\n\t\t\t}\n\t\t}\n\n\t\tfor _, provider := range toUpsertCustomProviders {\n\t\t\tif err := db.UpsertCustomProvider(tx, provider); err != nil {\n\t\t\t\treturn fmt.Errorf(\"error creating custom provider: %w\", err)\n\t\t\t}\n\t\t}\n\n\t\tfor _, modelPack := range toUpsertModelPacks {\n\t\t\tif err := db.UpsertModelPack(tx, modelPack); err != nil {\n\t\t\t\treturn fmt.Errorf(\"error creating model pack: %w\", err)\n\t\t\t}\n\t\t}\n\n\t\tif len(toDeleteCustomModelIds) > 0 {\n\t\t\tif err := db.DeleteCustomModels(tx, auth.OrgId, toDeleteCustomModelIds); err != nil {\n\t\t\t\treturn fmt.Errorf(\"error deleting custom models: %w\", err)","sourceCodeStart":275,"sourceCodeEnd":311,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/handlers/models.go#L275-L311","documentation":"Inside UpsertCustomModelsHandler's tx, db.UpsertCustomModel fails for one of the custom models being synced, aborting the whole transaction. DB insert/update failure for that model row (constraint, validation, connection).","triggerScenarios":"Thrown at app/server/handlers/models.go:293 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Identify which model failed from the wrapped error","Validate the model payload against DB constraints (unique ids/names)","Retry the upsert; the tx rollback keeps state consistent"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}