tconbeer / harlequin

The SQL IDE for Your Terminal.
https://harlequin.sh
MIT License
3.55k stars 77 forks source link

harlequin --config crashes with FileNotFoundError instead of creating new file #465

Closed erhhung closed 6 months ago

erhhung commented 6 months ago

Describe the bug

After answering various prompts,harlequin --config crashes with FileNotFoundError instead of creating a new config file.

To Reproduce

$ harlequin --config

? What config file do you want to create or update? ~/.config/harlequin/config.toml
? What would you like to name your profile? default
? Which adapter should this profile use? postgres
? What connection string(s) should this profile use?  Separate items by a space.
? What theme should this profile use? monokai
? How many rows should the data table show? 10000
? Show local files from a directory? (Leave blank to hide)
? Show cloud storage files?  Enter bucket name or URI (or `all`), or leave blank to hide cloud storage viewer.
? What locale should Harlequin use for formatting numbers?  Leave blank to use the system locale.
? Which of the following adapter options would you like to set? done
? Would you like to set a default profile? default
 We generated the following profile:
╭─────────────────────────────╮
│ default_profile = "default" │
│                             │
│ [profiles.default]          │
│ adapter = "postgres"        │
│ theme = "monokai"           │
│ limit = 10000               │
╰─────────────────────────────╯
? Save this profile? Yes

Traceback (most recent call last):
  File "/Users/erhhung/.local/bin/harlequin", line 10, in <module>
    sys.exit(harlequin())
             ^^^^^^^^^^^
  File "/Users/erhhung/Library/Application Support/pipx/venvs/harlequin/lib/python3.12/site-packages/harlequin/cli.py", line 358, in harlequin
    cli()
  File "/Users/erhhung/Library/Application Support/pipx/venvs/harlequin/lib/python3.12/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/erhhung/Library/Application Support/pipx/venvs/harlequin/lib/python3.12/site-packages/rich_click/rich_command.py", line 125, in main
    with self.make_context(prog_name, args, **extra) as ctx:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/erhhung/Library/Application Support/pipx/venvs/harlequin/lib/python3.12/site-packages/click/core.py", line 943, in make_context
    self.parse_args(ctx, args)
  File "/Users/erhhung/Library/Application Support/pipx/venvs/harlequin/lib/python3.12/site-packages/click/core.py", line 1408, in parse_args
    value, args = param.handle_parse_result(ctx, opts, args)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/erhhung/Library/Application Support/pipx/venvs/harlequin/lib/python3.12/site-packages/click/core.py", line 2400, in handle_parse_result
    value = self.process_value(ctx, value)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/erhhung/Library/Application Support/pipx/venvs/harlequin/lib/python3.12/site-packages/click/core.py", line 2362, in process_value
    value = self.callback(ctx, self, value)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/erhhung/Library/Application Support/pipx/venvs/harlequin/lib/python3.12/site-packages/harlequin/cli.py", line 117, in _config_wizard_callback
    wizard()
  File "/Users/erhhung/Library/Application Support/pipx/venvs/harlequin/lib/python3.12/site-packages/harlequin/config_wizard.py", line 25, in wizard
    _wizard()
  File "/Users/erhhung/Library/Application Support/pipx/venvs/harlequin/lib/python3.12/site-packages/harlequin/config_wizard.py", line 165, in _wizard
    file.write(config)
  File "/Users/erhhung/Library/Application Support/pipx/venvs/harlequin/lib/python3.12/site-packages/tomlkit/toml_file.py", line 57, in write
    with open(self._path, "w", encoding="utf-8", newline="") as f:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '~/.config/harlequin/config.toml'

Expected behavior

Actual behavior

Additional context

$ harlequin --version
harlequin, version 1.15.0

Installed Adapters:
  - duckdb, version 1.15.0
  - sqlite, version 1.15.0
  - postgres, version 0.2.2

Can you tell us more about your system?

tconbeer commented 6 months ago

Thanks for the report - I think this is because the parent directory did not exist; should be an easy fix.

erhhung commented 6 months ago

Thanks for the report - I think this is because the parent directory did not exist; should be an easy fix.

Actually, with the parent directory already created, it still fails with the same error. I believe Python just doesn't understand standard shell glob patterns like ~/:

GLOB_TILDE
              Carry out tilde expansion.  If a tilde ('~') is the only
              character in the pattern, or an initial tilde is followed
              immediately by a slash ('/'), then the home directory of
              the caller is substituted for the tilde.  If an initial
              tilde is followed by a username (e.g., "~andrea/bin"),
              then the tilde and username are substituted by the home
              directory of that user.  If the username is invalid, or
              the home directory cannot be determined, then no
              substitution is performed.