Skip to content

prettier-plugin-toml Crashes When Formatting a TOML File #487

@vivodi

Description

@vivodi

When attempting to format a pyproject.toml file, prettier fails with a panic error.

To Reproduce:

  1. Create a pyproject.toml file with the following content:

    [project.gui-scripts]
    flexget-headless = "flexget:main"  # This is useful on Windows to avoid a cmd popup
  2. Run the following command in your terminal:

    npx prettier --write pyproject.toml

Expected Behavior:

The TOML file should be formatted successfully without any errors.

Actual Behavior:

The command fails with the following error message and stack trace:

pyproject.tomlpanicked at /Users/JounQin/Workspaces/GitHub/taplo/crates/taplo/src/formatter/mod.rs:684:25:
assertion failed: entry.comment.is_none()

Stack:

Error
    at I.wbg.__wbg_new_abda76e883ba8a5f (C:\Users\vivodi\Projects\Flexget\node_modules\@taplo\lib\dist\index.js:2:4161)
    at console_error_panic_hook::Error::new::hd83448d5e1a1b88a (wasm://wasm/065ed00a:wasm-function[40242]:0x1249bc2)
    at console_error_panic_hook::hook_impl::h24434d5d3a31a46a (wasm://wasm/065ed00a:wasm-function[10411]:0xcf17fe)
    at console_error_panic_hook::hook::hb562c91cafc2c895 (wasm://wasm/065ed00a:wasm-function[59765]:0x12e59c7)
    at core::ops::function::Fn::call::h46d6beedf89bee9d (wasm://wasm/065ed00a:wasm-function[42879]:0x1275769)
    at std::panicking::rust_panic_with_hook::h8e8556df5e46d2ff (wasm://wasm/065ed00a:wasm-function[20551]:0xfc8712)
    at std::panicking::begin_panic_handler::{{closure}}::h142b9f459ded72d9 (wasm://wasm/065ed00a:wasm-function[25954]:0x10c54b9)
    at std::sys_common::backtrace::__rust_end_short_backtrace::h1c0d3278570375be (wasm://wasm/065ed00a:wasm-function[61550]:0x12e9f20)
    at rust_begin_unwind (wasm://wasm/065ed00a:wasm-function[42801]:0x12744d7)
    at core::panicking::panic_fmt::hbea4287e435ed8a3 (wasm://wasm/065ed00a:wasm-function[43645]:0x1280e86)



[error] pyproject.toml: Error: RuntimeError: unreachable
[error]     at M.format (C:\Users\vivodi\Projects\Flexget\node_modules\@taplo\lib\dist\index.js:2:35638065)
[error]     at format (file:///C:/Users/vivodi/Projects/Flexget/node_modules/prettier-plugin-toml/lib/index.js:10:21)
[error]     at async parse5 (file:///C:/Users/vivodi/Projects/Flexget/node_modules/prettier/index.mjs:16731:11)
[error]     at async coreFormat (file:///C:/Users/vivodi/Projects/Flexget/node_modules/prettier/index.mjs:17287:25)
[error]     at async formatWithCursor (file:///C:/Users/vivodi/Projects/Flexget/node_modules/prettier/index.mjs:17504:14)
[error]     at async formatFiles (file:///C:/Users/vivodi/Projects/Flexget/node_modules/prettier/internal/legacy-cli.mjs:4279:18)
[error]     at async main (file:///C:/Users/vivodi/Projects/Flexget/node_modules/prettier/internal/legacy-cli.mjs:4698:5)
[error]     at async Module.run (file:///C:/Users/vivodi/Projects/Flexget/node_modules/prettier/internal/legacy-cli.mjs:4641:5)

Environment:

  • prettier-plugin-toml version: 2.06
  • prettier version: 3.6.2
  • Node.js version: v22.14.0
  • Operating System: Windows 11

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions