{"record":{"id":"204096778f9ab256","repo":"hyperledger/fabric","slug":"no-list-open-cannot-close-list","errorCode":null,"errorMessage":"no list open, cannot close list","messagePattern":"no list open, cannot close list","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/ledgerutil/jsonrw/json_read_write.go","lineNumber":163,"sourceCode":"func (w *JSONFileWriter) OpenList() error {\n\tif w.listOpened {\n\t\treturn errors.Errorf(\"list already open, must close list before starting a new one\")\n\t}\n\n\tw.listOpened = true\n\tw.count = 0\n\t_, err := w.buffer.Write([]byte(\"[\\n\"))\n\tif err != nil {\n\t\treturn err\n\t}\n\n\treturn nil\n}\n\n// Close a json list\nfunc (w *JSONFileWriter) CloseList() error {\n\tif !w.listOpened {\n\t\treturn errors.Errorf(\"no list open, cannot close list\")\n\t}\n\n\tw.listOpened = false\n\t_, err := w.buffer.Write([]byte(\"]\\n\"))\n\tif err != nil {\n\t\treturn err\n\t}\n\n\treturn nil\n}\n\n// Add entries to an open json list\nfunc (w *JSONFileWriter) AddEntry(r any) error {\n\t// Need to open list before adding entries\n\tif !w.listOpened {\n\t\treturn errors.Errorf(\"no list open, cannot add entries\")\n\t}\n\t// Add commas for entries after the first entry in the list","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/internal/ledgerutil/jsonrw/json_read_write.go#L145-L181","documentation":"Validation guard in CommitInput.Validate: the -C (channelID) flag was not supplied to `peer lifecycle chaincode commit`, so the commit proposal has no target channel. Pure CLI usage error raised before proposal creation.","triggerScenarios":"Calling CloseList on a fresh writer, after the list was already closed, or when OpenList failed with an error and code proceeds to CloseList.","commonSituations":"Unbalanced open/close calls in cleanup or defer paths, duplicated close code, or ignoring an OpenList error earlier.","solutions":["Balance every OpenList with exactly one CloseList","Only call CloseList when OpenList returned nil","Note Close() refuses to flush while a list is open, so don't 'fix' it by adding extra CloseList calls; fix the pairing instead"],"exampleFix":"// before\nw.OpenList()\nw.CloseList()\nw.CloseList() // second call errors\n// after\nw.OpenList()\nw.CloseList()","handlingStrategy":"validation","validationCode":"if listWasOpened && !listWasClosed {\n\tif err := w.CloseList(); err != nil { return err }\n}","typeGuard":"func listNeedsClose(opened, closed bool) bool { return opened && !closed }","tryCatchPattern":"if err := w.CloseList(); err != nil {\n\treturn fmt.Errorf(\"close list: %w\", err)\n}","preventionTips":["Only close a list that was successfully opened","Use defer for exactly-once closing","Keep open/close calls structurally balanced in helpers"],"tags":["hyperledger-fabric","json","state-machine","api-misuse"],"backgroundTag":"json-writer-no-list-open","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"}