withfig / fig

Public issue tracker for Fig.
https://fig.io
MIT License
2.06k stars 63 forks source link

bug: syntax error near unexpected token `(' in bash #2696

Open yihou opened 1 year ago

yihou commented 1 year ago

Checks

Operating system

macOS 13.5 (22G74)

Expected behaviour

Works fine in bash, and there's shouldn't have any errors thrown on shell start up.

Actual behaviour

Getting error below on starting Bash shell:

bash: eval: line 2: syntax error near unexpected token `('
bash: eval: line 2: `  function () {'

Running fig doctor

$ fig doctor

✔ Everything looks good!

  Fig still not working? Run fig issue to let us know!
  Or, email us at hello@fig.io!

Steps to reproduce

This error occurs when bashrc.post.bash has been added in .bashrc.

After going thru a bit of digging, I found out that ~/.local/bin/fig init bash post --rcfile bashrc generate faulty bash scripts.

The error occurs at the beginning, as shown below:

if [ -z "${FIG_DOTFILES_SOURCED}" ]; then
  function () {

  }
  # alias -- =''
  FIG_DOTFILES_SOURCED=1
fi

the anonymous function from the generated bash scripts causes the error.

Environment

fig-details:
  - 2.16.0
hardware-info:
  - model:
  - model-id:
  - chip-id: Apple M2 Ultra
  - cores: 24
  - mem: 128.00 GB
os-info:
  - macOS 13.5.0 (22G74)
environment:
  - shell: /opt/homebrew/Cellar/bash/5.2.15/bin/bash
  - terminal: iterm
  - cwd: /Users/me
  - exe-path: /Users/me/.fig/bin/fig
  - install-method: brew
  - env-vars:
    - SHELL: /bin/zsh
    - __CFBundleIdentifier: com.googlecode.iterm2
    - FIG_SET_PARENT_CHECK: 1
    - FIGTERM_SESSION_ID: e72bac7e-4d53-4123-a931-de83d1294b68
    - FIG_SET_PARENT: e72bac7e-4d53-4123-a931-de83d1294b68
    - FIG_TERM: 2.16.0
    - TERM: xterm-256color
    - FIG_PID: 62890
    - PATH: /Users/me/.cargo/bin:/Users/me/Library/flutter/bin:/Users/me/.composer/vendor/bin:/Users/me/Library/Android/sdk/emulator:/Users/me/Library/Android/sdk/tools:/Users/me/Library/Android/sdk/tools/bin:/Users/me/Library/Android/sdk/platform-tools:/Users/me/Library/Android/sdk/build-tools/30.0.0
mschrage commented 1 year ago

Hey @yihou, everything inside of FIG_DOTFILES_SOURCED conditional are user-defined aliases and functions.

Open the dashboard and go to Dotfiles. You likely created an empty function block. Deleting that should resolve the issue.

yihou commented 1 year ago

Ahh thank you @mschrage, found the issue, it was due to a untitled function added in the Dotfiles configurations without the intention of adding it.

For better UX, can we avoid adding empty function block if the user hasn't fill in the field?

CleanShot 2023-09-16 at 00 02 28

chuckwondo commented 11 months ago

I ran into this same problem, and deleting the empty function block indeed resolves the problem.

However, I agree with @yihou that fig should be smart about this and automatically avoid inserting empty functions into the script.

filipef101 commented 1 month ago

To help future googlers, this was my issue: bash: eval: line 41: syntax error near unexpected token `(' solved by deleting the empty function Was causing vscode in particular to timeout unable to resolve shell environment