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

Semgrep crashes when working directory doesn't exist #4785

Closed
underyx opened this issue Mar 10, 2022 · 2 comments
Closed

Semgrep crashes when working directory doesn't exist #4785

underyx opened this issue Mar 10, 2022 · 2 comments

Comments

@underyx
Copy link
Member

underyx commented Mar 10, 2022

My shell was in a temporary directory that has been deleted since I cd'd in there. Running semgrep failed with this:

❯ semgrep -e 'echo' -l bash ~/r2c/semgrep/.github/post-checkout
Traceback (most recent call last):
  File "/opt/homebrew/bin/semgrep", line 33, in <module>
    sys.exit(load_entry_point('semgrep==0.84.0', 'console_scripts', 'semgrep')())
  File "/opt/homebrew/Cellar/semgrep/0.84.0/libexec/lib/python3.10/site-packages/semgrep/__main__.py", line 20, in main
    cli()
  File "/opt/homebrew/Cellar/semgrep/0.84.0/libexec/lib/python3.10/site-packages/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/opt/homebrew/Cellar/semgrep/0.84.0/libexec/lib/python3.10/site-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/opt/homebrew/Cellar/semgrep/0.84.0/libexec/lib/python3.10/site-packages/click/core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/opt/homebrew/Cellar/semgrep/0.84.0/libexec/lib/python3.10/site-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/opt/homebrew/Cellar/semgrep/0.84.0/libexec/lib/python3.10/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/opt/homebrew/Cellar/semgrep/0.84.0/libexec/lib/python3.10/site-packages/semgrep/commands/scan.py", line 816, in scan
    ) = semgrep.semgrep_main.main(
  File "/opt/homebrew/Cellar/semgrep/0.84.0/libexec/lib/python3.10/site-packages/semgrep/semgrep_main.py", line 298, in main
    all_rules = configs_obj.get_rules(no_rewrite_rule_ids)
  File "/opt/homebrew/Cellar/semgrep/0.84.0/libexec/lib/python3.10/site-packages/semgrep/config_resolver.py", line 312, in get_rules
    self._rename_rule_ids(configs)
  File "/opt/homebrew/Cellar/semgrep/0.84.0/libexec/lib/python3.10/site-packages/semgrep/config_resolver.py", line 347, in _rename_rule_ids
    f"{Config._convert_config_id_to_prefix(config_id)}{rule.id or MISSING_RULE_ID}"
  File "/opt/homebrew/Cellar/semgrep/0.84.0/libexec/lib/python3.10/site-packages/semgrep/config_resolver.py", line 335, in _convert_config_id_to_prefix
    at_path = Config._safe_relative_to(at_path, Path.cwd())
  File "/opt/homebrew/Cellar/python@3.10/3.10.2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/pathlib.py", line 991, in cwd
    return cls(cls._accessor.getcwd())
FileNotFoundError: [Errno 2] No such file or directory

so to reproduce:

  1. mkdir temp
  2. cd temp
  3. (in another shell) rm temp
  4. (in first shell) run semgrep

using semgrep 0.84

@r2c-demo
Copy link
Collaborator

@IagoAbal
Copy link
Contributor

Closed by #5548.

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

No branches or pull requests

4 participants