Skip to content

mdformat crashes if it can't find .mdformat.toml #565

Description

@outpaddling

Describe the bug

context
When I try to run mdformat 0.7.22 after a fresh install, it crashes, stating that a specific pathname is missing:

[snip, see full output below]
OSError: [Errno 5] Input/output error: '/net/.mdformat.toml'

configuration_file.html does not indicate that this config file is required, only that it's "allowed".

expectation
Instead of this confusing traceback, it would be good to output a specific error message:

Error: Cannot find .mdformat.toml. You must create this file in the current working directory or one of its ancestors.

Better, yet, maybe don't require this file at all, and run with defaults if it cannot be found.

bug
Here's an error message I ran into...

$ mdformat Home.md
Traceback (most recent call last):
  File "/usr/local/bin/mdformat", line 8, in <module>
    sys.exit(run())
             ^^^^^
  File "/usr/local/lib/python3.11/site-packages/mdformat/__main__.py", line 8, in run
    exit_code = mdformat._cli.run(sys.argv[1:])
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/mdformat/_cli.py", line 51, in run
    toml_opts, toml_path = read_toml(path.parent if path else Path.cwd())
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/mdformat/_conf.py", line 42, in read_toml_opts
    return read_toml_opts(parent_dir)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/mdformat/_conf.py", line 42, in read_toml_opts
    return read_toml_opts(parent_dir)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/mdformat/_conf.py", line 42, in read_toml_opts
    return read_toml_opts(parent_dir)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  [Previous line repeated 3 more times]
  File "/usr/local/lib/python3.11/site-packages/mdformat/_conf.py", line 38, in read_toml_opts
    if not conf_path.is_file():
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/pathlib.py", line 1267, in is_file
    return S_ISREG(self.stat().st_mode)
                   ^^^^^^^^^^^
  File "/usr/local/lib/python3.11/pathlib.py", line 1013, in stat
    return os.stat(self, follow_symlinks=follow_symlinks)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: [Errno 5] Input/output error: '/net/.mdformat.toml'

Reproduce the bug

  1. Run mdformat file.md.
  2. See traceback on terminal.

List your environment

mdformat --version 
mdformat 0.7.22

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions