{"record":{"id":"3433b291b1331d01","repo":"hyperledger/fabric","slug":"statefetcher-not-passed-in-init","errorCode":null,"errorMessage":"stateFetcher not passed in init","messagePattern":"stateFetcher not passed in init","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/handlers/validation/builtin/default_validation.go","lineNumber":128,"sourceCode":"\tfor _, dep := range dependencies {\n\t\tif deserializer, isIdentityDeserializer := dep.(vi.IdentityDeserializer); isIdentityDeserializer {\n\t\t\td = deserializer\n\t\t}\n\t\tif capabilities, isCapabilities := dep.(vc.Capabilities); isCapabilities {\n\t\t\tc = capabilities\n\t\t}\n\t\tif stateFetcher, isStateFetcher := dep.(vs.StateFetcher); isStateFetcher {\n\t\t\tsf = stateFetcher\n\t\t}\n\t\tif policyEvaluator, isPolicyFetcher := dep.(vp.PolicyEvaluator); isPolicyFetcher {\n\t\t\tpe = policyEvaluator\n\t\t}\n\t\tif collectionResources, isCollectionResources := dep.(plugindispatcher.CollectionResources); isCollectionResources {\n\t\t\tcor = collectionResources\n\t\t}\n\t}\n\tif sf == nil {\n\t\treturn errors.New(\"stateFetcher not passed in init\")\n\t}\n\tif d == nil {\n\t\treturn errors.New(\"identityDeserializer not passed in init\")\n\t}\n\tif c == nil {\n\t\treturn errors.New(\"capabilities not passed in init\")\n\t}\n\tif pe == nil {\n\t\treturn errors.New(\"policy fetcher not passed in init\")\n\t}\n\tif cor == nil {\n\t\treturn errors.New(\"collection resources not passed in init\")\n\t}\n\n\tv.Capabilities = c\n\tv.TxValidatorV1_2 = v12.New(c, sf, d, pe)\n\tv.TxValidatorV1_3 = v13.New(c, sf, d, pe)\n\tv.TxValidatorV2_0 = v20.New(c, sf, d, pe, cor)","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/handlers/validation/builtin/default_validation.go#L110-L146","documentation":"Init() of the built-in validation (VSCC) handler returns this error when the StateFetcher dependency was not supplied. The handler needs a StateFetcher to read chaincode state (e.g. instantiation policies and collection configs) during transaction validation, so it refuses to initialize without one. This is a startup-time wiring error, not a runtime failure.","triggerScenarios":"Calling Init() with sf == nil: constructing the DefaultValidation handler (or the v12 validator built on it) without registering a StateFetcher in the dependency map passed to Init.","commonSituations":"Booting a peer with a custom validation plugin assembly that forgets to provide the StateFetcher; unit-testing the validator with a partial dependency set; refactoring dependency injection code and dropping one key.","solutions":["Pass a valid StateFetcher in the dependencies map supplied to Init()","Check that the dependency factory/builder that constructs the validation handler is invoked after the ledger/StateFetcher is available","Add an early assertion in tests that all of sf, d, c, pe, cor are non-nil before calling Init"],"exampleFix":"// before\nhandler := &DefaultValidation{}\nerr := handler.Init(nil, deserializer, capabilities, policyEvaluator, collectionResources)\n// after\nsf := &statefetcher.Fetcher{...}\nerr := handler.Init(sf, deserializer, capabilities, policyEvaluator, collectionResources)","handlingStrategy":"validation","validationCode":"if sf == nil {\n    return errors.New(\"cannot init validation handler: StateFetcher dependency is nil\")\n}\nerr := handler.Init(sf, d, c, pe, cor)","typeGuard":"func depsComplete(sf StateFetcher) bool { return sf != nil }","tryCatchPattern":null,"preventionTips":["Always build validation handler dependencies through a single factory that guarantees all five deps","Assert non-nil dependencies in unit tests before Init","Review DI wiring after refactors with a checklist of sf, d, c, pe, cor"],"tags":["go","initialization","dependency-injection","vscc"],"backgroundTag":"missing-dependency-in-init","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}