resholve icon indicating copy to clipboard operation
resholve copied to clipboard

parsing aliases with `=` inside them fails with `ValueError: too many values to unpack`

Open kasimeka opened this issue 1 year ago • 1 comments

resholve fails to parse aliases with = chars in their definition because aliases are split with .split('=') here, this breaks derivation realisation whether or not solutions.default.fix.aliases is set to true.

example alias that triggers the issue:

ssh_prod='ssh $(AWS_REGION=us-east-1 ssm-machine jump)'

error emitted during evaluation:

>   File "/nix/store/bmnmsvgqamwdcvybicmw5hkv1lanihnh-resholve-0.10.5/bin/.resholve-wrapped", line 3509, in handle_builtin_alias
>     alias, definition = word.strip("\"='").split("=")
> ValueError: too many values to unpack

patching resholve as follows to only split on the first occurrence of = fixed it for me, I'm willing to create a PR for this if you don't mind.

diff --git a/resholve b/resholve
index c163fa9..e0581bc 100755
--- a/resholve
+++ b/resholve
@@ -3506,7 +3506,7 @@ class RecordCommandlike(object):
             if word.ok:
                 # not dynamic; more examples in tests/aliases.sh, but:
                 # 'd', 'echo $SOURCE_DATE_EPOCH'
-                alias, definition = word.strip("\"='").split("=")
+                alias, definition = word.strip("\"='").split("=", 1)
                 # TODO: maybe below deserves an explicit API
                 cmdlikes[alias].alias = True
                 commandlike = definition.split()[0]

kasimeka avatar Oct 29 '24 07:10 kasimeka

Thanks for the patch and PR offer.

I think you can hold off on the PR for now while I see if I can turn around a more general fix for my own corner-cutting.

abathur avatar Oct 29 '24 15:10 abathur