{"record":{"id":"63d914ab298c8a69","repo":"ethereum/go-ethereum","slug":"trie-newstatetrie-called-without-a-database","errorCode":null,"errorMessage":"trie.NewStateTrie called without a database","messagePattern":"trie\\.NewStateTrie called without a database","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"trie/secure_trie.go","lineNumber":80,"sourceCode":"// New and must have an attached database. The database also stores\n// the preimage of each key if preimage recording is enabled.\n//\n// StateTrie is not safe for concurrent use.\ntype StateTrie struct {\n\ttrie        Trie\n\tdb          database.NodeDatabase\n\tpreimages   preimageStore\n\tsecKeyCache map[common.Hash][]byte\n}\n\n// NewStateTrie creates a trie with an existing root node from a backing database.\n//\n// If root is the zero hash or the sha3 hash of an empty string, the\n// trie is initially empty. Otherwise, New will panic if db is nil\n// and returns MissingNodeError if the root node cannot be found.\nfunc NewStateTrie(id *ID, db database.NodeDatabase) (*StateTrie, error) {\n\tif db == nil {\n\t\tpanic(\"trie.NewStateTrie called without a database\")\n\t}\n\ttrie, err := New(id, db)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\ttr := &StateTrie{\n\t\ttrie:        *trie,\n\t\tdb:          db,\n\t\tsecKeyCache: make(map[common.Hash][]byte),\n\t}\n\n\t// link the preimage store if it's supported\n\tif preimages, ok := db.(preimageStore); ok && preimages.PreimageEnabled() {\n\t\ttr.preimages = preimages\n\t}\n\treturn tr, nil\n}\n","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/ethereum/go-ethereum/blob/6bb0588ad8e7f922e4ad5580f51265a4097af08f/trie/secure_trie.go#L62-L98","documentation":"Error \"trie.NewStateTrie called without a database\" thrown in ethereum/go-ethereum.","triggerScenarios":"Calling trie.NewStateTrie(id, nil) — constructing a state trie without a backing node database.","commonSituations":"Test setups or new code paths that forget to wire the triedb/database dependency into the trie constructor.","solutions":["Always pass a non-nil database to trie.NewStateTrie. Obtain it from the chain/state database (e.g., state.NewDatabase or triedb) instead of nil.","Guard construction: check db != nil before calling NewStateTrie and return an error to the caller."],"exampleFix":"if db == nil {\n    return nil, errors.New(\"state trie requires a database\")\n}\ntr, err := trie.NewStateTrie(id, db)","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"6bb0588ad8e7f922e4ad5580f51265a4097af08f","analyzedAt":"2026-08-15T10:06:53.996Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}