rajasegar / alacritty-themes

:rainbow: :lollipop: Themes :candy: :heart_eyes: for Alacritty: A cross-platform GPU-accelerated Terminal emulator
MIT License
696 stars 71 forks source link

current flag bug #73

Closed mesalilac closed 2 years ago

mesalilac commented 2 years ago

Describe the bug

'alacritty-themes' does not catch readFileSync error in line: https://github.com/rajasegar/alacritty-themes/blob/7679518e13d448b4f59495bbc5e95a8237196976/index.js#L48

Error output:

node:internal/fs/utils:670
throw new ERR_INVALID_ARG_TYPE(propName, ['string', 'Buffer', 'URL'], path);
    ^
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received undefined

To Reproduce

Steps to reproduce the behavior:

  1. Delete alacritty config file
  2. Run alacritty-themes --current
JuanVqz commented 2 years ago

@Senpai-10 Hi! Thank you for opening this issue and you are right, it didn't catch the error!

What do you suggest or how can we solve this problem? Thank you and BTW, we are open for PRs!

mesalilac commented 2 years ago

https://github.com/rajasegar/alacritty-themes/blob/c727b616a0a0965ad163c22d543471a0697f6150/src/helpers/index.js#L63-L69

@JuanVqz alacrittyConfigPath function returns undefined if no alacritty configuration file is found, this is why fs.readFileSync(alacrittyConfigPath(), 'utf8'); does not work

we can fix this is by checking if alacrittyConfigPath() return value is not undefined before trying to read from the file

Like this:

function getCurrentTheme() {
  if (!alacrittyConfigPath()) {
    console.log(
      'No Alacritty configuration file found\nRun: `alacritty-themes -C` to create one'
    );
    exit(1);
  }
  const themeFile = fs.readFileSync(alacrittyConfigPath(), 'utf8');
  const themeDoc = YAML.parse(themeFile);

  return themeDoc.theme ? themeDoc.theme : 'default';
}