Skip to content

espefuse.py can't create a json file (ESPTOOL-1367) #1180

Closed

Description

@S3bz0n3

Operating System

Windows11

Esptool Version

V5.5.4

Python Version

3.14.4

Chip Description

ESP32

Device Description

I'm using the ESP32 Wrover E

Hardware Configuration

SPI and I2C several LEDs and GPIOS are used

How is Esptool Run

VS Code

Full Esptool Command Line that Was Run

C:\Espressif\tools\python\v5.5.4\venv\Scripts\python.exe D:\ESP.espressif\v5.5.4\esp-idf\components\esptool_py\esptool\espefuse.py -p COM4 summary --format json --file D:\test.json

Esptool Output

C:\Espressif\tools\python\v5.5.4\venv\Scripts\python.exe D:\ESP\.espressif\v5.5.4\esp-idf\components\esptool_py\esptool\espefuse.py -p COM4 summary --format json --file D:\test.json
espefuse.py v4.12.0
Connecting....
Detecting chip type... ESP32

=== Run "summary" command ===
Saving efuse values to D:\test.json

More Information

The root cause is a missing file.close() call in the JSON output path of the summary() method in espefuse/efuse/base_operations.py.

The human-readable output path correctly closes the file:
if human_output:
for line in summary_efuse:
log.print(escape(line), file=file)
if file != sys.stdout:
file.close() # ✅ file is closed, buffer is flushed
log.print("Done")
elif format == "json":
json.dump(json_efuse, file, sort_keys=True, indent=4)
log.print("") # ❌ file is never closed, buffer is lost

Suggested fix
elif format == "json":
json.dump(json_efuse, file, sort_keys=True, indent=4)
if file != sys.stdout:
file.close()
log.print("")

Other Steps to Reproduce

python -m espefuse --port COM4 summary --format json --file output.json

Command reports success: "Saving efuse values to output.json"

But: output.json is 0 bytes

I Have Read the Troubleshooting Guide

  • I confirm I have read the troubleshooting guide.

Activity

  1. github-actions commented on Jul 29, 2026

    @github-actions

    Hi @S3bz0n3! Please be aware that (1) the following suggestions are generated by a bot and haven't been fact-checked by Espressif Systems, (2) burning eFuses and enabling security features are irreversible operations and can damage your ESP32 device. We hope that this message will help you until an Espressif Engineer looks at your issue.


    Analysis of the Issue

    The user has correctly identified a real bug in espefuse/efuse/base_operations.py. Looking at the relevant code from the knowledge sources, the issue is clear:

    [base_operations.py]

    if human_output:
        for line in summary_efuse:
            log.print(escape(line), file=file)
        if file != sys.stdout:
            file.close()       # ✅ file is closed and buffer is flushed
            log.print("Done")
    elif format == "json":
        json.dump(json_efuse, file, sort_keys=True, indent=4)
        log.print("")           # ❌ file is never closed, buffer is never flushed

    The human_output path correctly calls file.close() when writing to a file (not stdout), which flushes the write buffer and ensures data is persisted to disk. The json path is missing this call entirely, so the buffered JSON data is never flushed/written, resulting in a 0-byte output file.

    Suggested Fix

    The fix proposed in the issue is correct:

    elif format == "json":
        json.dump(json_efuse, file, sort_keys=True, indent=4)
        if file != sys.stdout:
            file.close()
        log.print("")

    This mirrors the existing pattern used in the human_output branch and ensures the file buffer is flushed and the file handle is properly closed when writing JSON to a file.

    This is a straightforward and valid bug report with a well-reasoned fix. It would be worth submitting a pull request with this one-line addition to espefuse/efuse/base_operations.py.

  2. changed the title [-]espefuse.py can't create a json file[/-] [+]espefuse.py can't create a json file (ESPTOOL-1367)[/+] on Jul 29, 2026
  3. peterdragun commented on Jul 30, 2026

    @peterdragun
    Collaborator

    Hi @S3bz0n3 thank you for the report. We will fix this ASAP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions