Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken error message when building project #74

Open
mathrick opened this issue Mar 4, 2025 · 4 comments
Open

Broken error message when building project #74

mathrick opened this issue Mar 4, 2025 · 4 comments

Comments

@mathrick
Copy link

mathrick commented Mar 4, 2025

Please see the attached zip for a repro project

In some situations, the plugin fails with a completely meaningless error message:

$ poetry build
'name'

Steps to reproduce:

  1. Unzip the repro project
  2. cd /tmp/poetry-monoranger-repro
  3. poetry install
  4. poetry build

Traceback shows it's an unhandled KeyError:

$ poetry -vvv build
Trying to detect current active python executable as specified in the config.
Found: /home/mkatafiasz/.pyenv/versions/repro/bin/python
Using virtualenv: /home/mkatafiasz/.pyenv/versions/repro

  Stack trace:

  10  ~/.local/share/pipx/venvs/poetry/lib/python3.12/site-packages/cleo/application.py:327 in run
       325│ 
       326│             try:
     → 327│                 exit_code = self._run(io)
       328│             except BrokenPipeError:
       329│                 # If we are piped to another process, it may close early and send a

   9  ~/.local/share/pipx/venvs/poetry/lib/python3.12/site-packages/poetry/console/application.py:236 in _run
       234│ 
       235│         with directory(self._working_directory):
     → 236│             exit_code: int = super()._run(io)
       237│ 
       238│         return exit_code

   8  ~/.local/share/pipx/venvs/poetry/lib/python3.12/site-packages/cleo/application.py:431 in _run
       429│             io.input.interactive(interactive)
       430│ 
     → 431│         exit_code = self._run_command(command, io)
       432│         self._running_command = None
       433│ 

   7  ~/.local/share/pipx/venvs/poetry/lib/python3.12/site-packages/cleo/application.py:473 in _run_command
       471│ 
       472│         if error is not None:
     → 473│             raise error
       474│ 
       475│         return terminate_event.exit_code

   6  ~/.local/share/pipx/venvs/poetry/lib/python3.12/site-packages/cleo/application.py:454 in _run_command
       452│ 
       453│         try:
     → 454│             self._event_dispatcher.dispatch(command_event, COMMAND)
       455│ 
       456│             if command_event.command_should_run():

   5  ~/.local/share/pipx/venvs/poetry/lib/python3.12/site-packages/cleo/events/event_dispatcher.py:26 in dispatch
        24│ 
        25│         if listeners:
     →  26│             self._do_dispatch(listeners, event_name, event)
        27│ 
        28│         return event

   4  ~/.local/share/pipx/venvs/poetry/lib/python3.12/site-packages/cleo/events/event_dispatcher.py:85 in _do_dispatch
        83│                 break
        84│ 
     →  85│             listener(event, event_name, self)
        86│ 
        87│     def _sort_listeners(self, event_name: str) -> None:

   3  .poetry/plugins/poetry_monoranger_plugin/plugin.py:130 in console_command_event_listener
       128│             from poetry_monoranger_plugin.path_dep_pinner import PathDepPinner
       129│ 
     → 130│             PathDepPinner(self.plugin_conf).execute(event)
       131│ 
       132│         if ExportCommand is not None and isinstance(command, ExportCommand):

   2  .poetry/plugins/poetry_monoranger_plugin/path_dep_pinner.py:56 in execute
        54│ 
        55│         main_deps_group = poetry.package.dependency_group(MAIN_GROUP)
     →  56│         self._pin_dep_grp(main_deps_group, io)
        57│ 
        58│     def _pin_dep_grp(self, dep_gpr: DependencyGroup, io: IO):

   1  .poetry/plugins/poetry_monoranger_plugin/path_dep_pinner.py:63 in _pin_dep_grp
        61│         for dependency in directory_deps:
        62│             try:
     →  63│                 pinned = self._pin_dependency(dependency)
        64│             except (RuntimeError, ValueError) as e:
        65│                 io.write_line(f"Could not pin dependency {dependency.name}: {e!s}")

  KeyError

  'name'

  at .poetry/plugins/poetry_monoranger_plugin/path_dep_pinner.py:133 in _pin_dependency
      129│         """
      130│         dep_pyproject: PyProjectTOML = self._get_dependency_pyproject(dependency)
      131│ 
      132│         try:
    → 133│             name = cast(str, dep_pyproject.poetry_config["name"])
      134│             version = cast(str, dep_pyproject.poetry_config["version"])
      135│         except PyProjectError:
      136│             # Fallback to the project section since Poetry V2 also supports PEP 621 pyproject.toml files
      137│             name = cast(str, dep_pyproject.data["project"]["name"])

poetry-monoranger-repro.zip

@ag14774
Copy link
Owner

ag14774 commented Mar 5, 2025

Thank you! I will investigate this more but I think PR #70 might already be the solution to this!

@mathrick
Copy link
Author

mathrick commented Mar 5, 2025

Makes sense, thanks.

@mathrick
Copy link
Author

mathrick commented Mar 5, 2025

Do you think this should be reported upstream with Poetry to improve their reporting of unhandled exceptions?

@ag14774
Copy link
Owner

ag14774 commented Mar 5, 2025

I believe this is purely an issue with this plugin since I am incorrectly identifying whether a project uses the new-style of pyproject.toml or the old-style

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants