hyperledger/fabric · error

no list open, cannot close list

Error message

no list open, cannot close list

What it means

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.

Source

Thrown at internal/ledgerutil/jsonrw/json_read_write.go:163

func (w *JSONFileWriter) OpenList() error {
	if w.listOpened {
		return errors.Errorf("list already open, must close list before starting a new one")
	}

	w.listOpened = true
	w.count = 0
	_, err := w.buffer.Write([]byte("[\n"))
	if err != nil {
		return err
	}

	return nil
}

// Close a json list
func (w *JSONFileWriter) CloseList() error {
	if !w.listOpened {
		return errors.Errorf("no list open, cannot close list")
	}

	w.listOpened = false
	_, err := w.buffer.Write([]byte("]\n"))
	if err != nil {
		return err
	}

	return nil
}

// Add entries to an open json list
func (w *JSONFileWriter) AddEntry(r any) error {
	// Need to open list before adding entries
	if !w.listOpened {
		return errors.Errorf("no list open, cannot add entries")
	}
	// Add commas for entries after the first entry in the list

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Balance every OpenList with exactly one CloseList
  2. Only call CloseList when OpenList returned nil
  3. Note Close() refuses to flush while a list is open, so don't 'fix' it by adding extra CloseList calls; fix the pairing instead

Example fix

// before
w.OpenList()
w.CloseList()
w.CloseList() // second call errors
// after
w.OpenList()
w.CloseList()
Defensive patterns

Strategy: validation

Validate before calling

if listWasOpened && !listWasClosed {
	if err := w.CloseList(); err != nil { return err }
}

Type guard

func listNeedsClose(opened, closed bool) bool { return opened && !closed }

Try / catch

if err := w.CloseList(); err != nil {
	return fmt.Errorf("close list: %w", err)
}

Prevention

When it happens

Trigger: Calling CloseList on a fresh writer, after the list was already closed, or when OpenList failed with an error and code proceeds to CloseList.

Common situations: Unbalanced open/close calls in cleanup or defer paths, duplicated close code, or ignoring an OpenList error earlier.

Related errors


AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04). Data as JSON: /api/errors/204096778f9ab256. Report an issue: GitHub.