{"record":{"id":"de9fa49843fb82c0","repo":"pulumi/pulumi","slug":"registry-mock-downloadtemplatef-not-implemented","errorCode":null,"errorMessage":"registry.Mock.DownloadTemplateF not implemented","messagePattern":"registry\\.Mock\\.DownloadTemplateF not implemented","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/registry/mock.go","lineNumber":81,"sourceCode":") (apitype.TemplateMetadata, error) {\n\tif m.GetTemplateF == nil {\n\t\tpanic(\"registry.Mock.GetTemplateF not implemented\")\n\t}\n\treturn m.GetTemplateF(ctx, source, publisher, name, version)\n}\n\nfunc (m Mock) ListTemplates(\n\tctx context.Context, opts ListTemplatesOptions,\n) iter.Seq2[apitype.ListTemplatesResponse, error] {\n\tif m.ListTemplatesF == nil {\n\t\tpanic(\"registry.Mock.ListTemplatesF not implemented\")\n\t}\n\treturn m.ListTemplatesF(ctx, opts)\n}\n\nfunc (m Mock) DownloadTemplate(ctx context.Context, downloadURL string) (io.ReadCloser, error) {\n\tif m.ListTemplatesF == nil {\n\t\tpanic(\"registry.Mock.DownloadTemplateF not implemented\")\n\t}\n\treturn m.DownloadTemplateF(ctx, downloadURL)\n}\n","sourceCodeStart":63,"sourceCodeEnd":85,"githubUrl":"https://github.com/pulumi/pulumi/blob/793f7b2e160db4321fb7fb6b0607461e01cb251e/pkg/registry/mock.go#L63-L85","documentation":"Mock.DownloadTemplate panics when its backing function is not implemented. Note the guard checks the wrong field: it tests m.ListTemplatesF instead of m.DownloadTemplateF, so a Mock with ListTemplatesF set but DownloadTemplateF nil still panics with this (misleading) message, and a Mock with DownloadTemplateF set but ListTemplatesF nil panics here even though DownloadTemplateF exists. This is a copy-paste bug in pkg/registry/mock.go:80.","triggerScenarios":"Calling Mock.DownloadTemplate when DownloadTemplateF is nil and ListTemplatesF is also nil (correct panic, wrong message), or when ListTemplatesF is non-nil but DownloadTemplateF is nil (panic that misreports ListTemplatesF as the culprit); also any Mock whose guard misfires because only ListTemplatesF was configured.","commonSituations":"Test fixture stubs template listing but not template download; copying the Mock from a test that only lists templates; confusion when the panic message points at ListTemplatesF while the actual missing field is DownloadTemplateF.","solutions":["Set DownloadTemplateF on the Mock before calling DownloadTemplate","Fix the guard to check m.DownloadTemplateF instead of m.ListTemplatesF in pkg/registry/mock.go:80","Use a Mock constructor that initializes every function field with safe defaults"],"exampleFix":"// before (mock.go:80)\nif m.ListTemplatesF == nil {\n  panic(\"registry.Mock.DownloadTemplateF not implemented\")\n}\n// after\nif m.DownloadTemplateF == nil {\n  panic(\"registry.Mock.DownloadTemplateF not implemented\")\n}","handlingStrategy":"validation","validationCode":"if mock.DownloadTemplateF == nil {\n  return fmt.Errorf(\"test setup incomplete: DownloadTemplateF must be set before downloading templates\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Fix the guard in pkg/registry/mock.go to check m.DownloadTemplateF, not m.ListTemplatesF","Build Mock instances through a constructor that defaults every function field","Add a unit test exercising each Mock method with a nil-field Mock to catch wrong-field guards"],"tags":["go","panic","test-mock","copy-paste-bug"],"backgroundTag":"unimplemented-mock-function","analyzedSha":"793f7b2e160db4321fb7fb6b0607461e01cb251e","analyzedAt":"2026-08-31T09:36:43.099Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}