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

:? expansions break caching #22

Open
dimo414 opened this issue Sep 20, 2020 · 0 comments
Open

:? expansions break caching #22

dimo414 opened this issue Sep 20, 2020 · 0 comments

Comments

@dimo414
Copy link
Owner

dimo414 commented Sep 20, 2020

$ foo() { echo 'Checking $1'; : "${1:?}"; }

$ foo
Checking $1
-bash: 1: parameter null or not set

$ bc::cache foo

$ foo

$ echo $?
1

$ (set -x; client_type) |& tail -n 3
++ mktemp -d /tmp/bash-cache-0.8-274474/data/60/XXXXXXXXXX
+ cache=/tmp/bash-cache-0.8-274474/data/60/vZDnRVXVA1
+ bc::orig::client_type

The failing ${1:?} expansion causes the shell to exit (in an interactive session it doesn't exit, but it does immediately terminate processing and return to the prompt, as if exiting). This prevents the function from being cached properly and, notably, suppresses the error message from being written to stderr.

Invoking the cached function in a subshell (i.e. ( "bc::orig::${func}" "${args[@]}" ) > "${cache}/out" 2> "${cache}/err" in bc::_write_cache) is sufficient to work-around this problem, but adding an extra subshell to every cache write would be an expensive solution.

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

1 participant