abathur / resholve

a shell resolver? :) (find and resolve shell script dependencies)
MIT License
231 stars 5 forks source link

Exec lacks a required argument #23

Closed toonn closed 3 years ago

toonn commented 3 years ago

Got the following traceback, command included.

[nix-shell:~/src/nb]$ resholve --interpreter=$(which bash) --inputs='' --keep='source:$NBRC_PATH;$__file $PAGER' nb
    eval "describe \"${_alias}\" \"\$____describe_${_subcommand}\""
         ^
/Users/toonn/src/nb/nb:1116: FEEDBACK WANTED: Letting quoted 'eval' through for now. Not sure if this is 'right' or not. Weigh in @ https://github.com/abathur/resholve/issues/2
    eval "_${_alias}() { _${_subcommand} \"\${@}\"; }"
         ^
/Users/toonn/src/nb/nb:1117: FEEDBACK WANTED: Letting quoted 'eval' through for now. Not sure if this is 'right' or not. Weigh in @ https://github.com/abathur/resholve/issues/2
Traceback (most recent call last):
  File "/nix/store/v5x6bbli7j8mn58mmca54jy3rwcy4rkz-resholve-0.4.2/bin/.resholve-wrapped", line 1983, in <module>
    sys.exit(punshow())
  File "/nix/store/v5x6bbli7j8mn58mmca54jy3rwcy4rkz-resholve-0.4.2/bin/.resholve-wrapped", line 621, in punshow
    epilogue=args.epilogue,
  File "/nix/store/v5x6bbli7j8mn58mmca54jy3rwcy4rkz-resholve-0.4.2/bin/.resholve-wrapped", line 485, in resolve_script
    script_path, shebang=shebang, prologue=prologue, epilogue=epilogue
  File "/nix/store/v5x6bbli7j8mn58mmca54jy3rwcy4rkz-resholve-0.4.2/bin/.resholve-wrapped", line 1394, in __init__
    self.Visit(node)
  File "/nix/store/v5x6bbli7j8mn58mmca54jy3rwcy4rkz-resholve-0.4.2/bin/.resholve-wrapped", line 1958, in Visit
    self.VisitChildren(node)
  File "/nix/store/v5x6bbli7j8mn58mmca54jy3rwcy4rkz-resholve-0.4.2/bin/.resholve-wrapped", line 1973, in VisitChildren
    self.Visit(item)
  File "/nix/store/v5x6bbli7j8mn58mmca54jy3rwcy4rkz-resholve-0.4.2/bin/.resholve-wrapped", line 1958, in Visit
    self.VisitChildren(node)
  File "/nix/store/v5x6bbli7j8mn58mmca54jy3rwcy4rkz-resholve-0.4.2/bin/.resholve-wrapped", line 1977, in VisitChildren
    self.Visit(child)
  File "/nix/store/v5x6bbli7j8mn58mmca54jy3rwcy4rkz-resholve-0.4.2/bin/.resholve-wrapped", line 1958, in Visit
    self.VisitChildren(node)
  File "/nix/store/v5x6bbli7j8mn58mmca54jy3rwcy4rkz-resholve-0.4.2/bin/.resholve-wrapped", line 1973, in VisitChildren
    self.Visit(item)
  File "/nix/store/v5x6bbli7j8mn58mmca54jy3rwcy4rkz-resholve-0.4.2/bin/.resholve-wrapped", line 1958, in Visit
    self.VisitChildren(node)
  File "/nix/store/v5x6bbli7j8mn58mmca54jy3rwcy4rkz-resholve-0.4.2/bin/.resholve-wrapped", line 1973, in VisitChildren
    self.Visit(item)
  File "/nix/store/v5x6bbli7j8mn58mmca54jy3rwcy4rkz-resholve-0.4.2/bin/.resholve-wrapped", line 1958, in Visit
    self.VisitChildren(node)
  File "/nix/store/v5x6bbli7j8mn58mmca54jy3rwcy4rkz-resholve-0.4.2/bin/.resholve-wrapped", line 1973, in VisitChildren
    self.Visit(item)
  File "/nix/store/v5x6bbli7j8mn58mmca54jy3rwcy4rkz-resholve-0.4.2/bin/.resholve-wrapped", line 1958, in Visit
    self.VisitChildren(node)
  File "/nix/store/v5x6bbli7j8mn58mmca54jy3rwcy4rkz-resholve-0.4.2/bin/.resholve-wrapped", line 1977, in VisitChildren
    self.Visit(child)
  File "/nix/store/v5x6bbli7j8mn58mmca54jy3rwcy4rkz-resholve-0.4.2/bin/.resholve-wrapped", line 1958, in Visit
    self.VisitChildren(node)
  File "/nix/store/v5x6bbli7j8mn58mmca54jy3rwcy4rkz-resholve-0.4.2/bin/.resholve-wrapped", line 1973, in VisitChildren
    self.Visit(item)
  File "/nix/store/v5x6bbli7j8mn58mmca54jy3rwcy4rkz-resholve-0.4.2/bin/.resholve-wrapped", line 1957, in Visit
    self._Visit(node)
  File "/nix/store/v5x6bbli7j8mn58mmca54jy3rwcy4rkz-resholve-0.4.2/bin/.resholve-wrapped", line 1951, in _Visit
    self._visit_command_Simple(node)
  File "/nix/store/v5x6bbli7j8mn58mmca54jy3rwcy4rkz-resholve-0.4.2/bin/.resholve-wrapped", line 1661, in _visit_command_Simple
    node,
Exception: ('Trying to handle exec but it lacks a required argument', (command.Simple
  words: [(compound_word parts:[(Token id:Id.Lit_Chars span_id:22274 val:exec)])]
  redirects: [
    (redir
      op: (Token id:Id.Redir_Great span_id:22276 val:'3>')
      loc: (redir_loc.Fd fd:3)
      arg: 
        (compound_word
          parts: [
            (double_quoted
              left: (Token id:Id.Left_DoubleQuote span_id:22278 val:'"')
              parts: [
                (braced_var_sub
                  token: (Token id:Id.VSub_Name span_id:22280 val:_temp_file)
                  spids: [22279 22281]
                )
              ]
              spids: [22278 22282]
            )
          ]
        )
    )
  ]
  do_fork: T
))
abathur commented 3 years ago

Egh. Ok. We may be stuck here for a little bit, but I'll bump it up my to-do list.

In this case, it's breaking on some no-arg uses of exec to manipulate FDs, which I obviously didn't have in mind.

Unfortunately, the fix is tied up with some abstract/architectural decisions I haven't settled on a solution to. I'm glad you hit it, though--it's a case I hadn't considered, so it might help make the solution more obvious.

Sorry to leave you blocked--I'll update you when I have something.

toonn commented 3 years ago

Np, glad to be of service. I'll use the traditional methods for now.

abathur commented 3 years ago

I'm ~roughly ready (sans bugfixes, review, and perhaps bikeshedding) to land the work mentioned here.

I'm not sure if you're set up to give this a quick test, but if so it would be good to see if this works for your case. You should be able to override/overlay with the same source in https://github.com/abathur/resholve/commit/c4140c28a36d6f9e9b05c9dae03ede2fe2bd57be#diff-9c0c6e6c25883f63765fedcfbedb4bf4c12784db049728c5c7c0496d269c21aa

I also have a nascent nixpkgs commit in https://github.com/abathur/nixpkgs/commit/14b00b18ae3cdc8b18bc49061a1ba8ad46b09630 if that's easier (though I'm not super-current with latest nixpkgs.)

Fair warning that I'm still likely to be force-pushing this work some. The latest code will generally be available at https://github.com/abathur/resholve/tree/subexecers even if I've blown away a specific commit.

abathur commented 3 years ago

I have yet to initiate a PR for updating this in nixpkgs yet, but the release of 0.6.0 should fix this issue if you happen to overlay it in.