-
Notifications
You must be signed in to change notification settings - Fork 0
tf 4 #19
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
base: main
Are you sure you want to change the base?
tf 4 #19
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -20,17 +20,9 @@ def _get_functions(overridden): | |||||||||||||||||||||||||||||||||||||||||||||
| def _get_aliases(overridden): | ||||||||||||||||||||||||||||||||||||||||||||||
| aliases = {} | ||||||||||||||||||||||||||||||||||||||||||||||
| proc = Popen(['fish', '-ic', 'alias'], stdout=PIPE, stderr=DEVNULL) | ||||||||||||||||||||||||||||||||||||||||||||||
| alias_out = proc.stdout.read().decode('utf-8').strip() | ||||||||||||||||||||||||||||||||||||||||||||||
| if not alias_out: | ||||||||||||||||||||||||||||||||||||||||||||||
| return aliases | ||||||||||||||||||||||||||||||||||||||||||||||
| for alias in alias_out.split('\n'): | ||||||||||||||||||||||||||||||||||||||||||||||
| for separator in (' ', '='): | ||||||||||||||||||||||||||||||||||||||||||||||
| split_alias = alias.replace('alias ', '', 1).split(separator, 1) | ||||||||||||||||||||||||||||||||||||||||||||||
| if len(split_alias) == 2: | ||||||||||||||||||||||||||||||||||||||||||||||
| name, value = split_alias | ||||||||||||||||||||||||||||||||||||||||||||||
| break | ||||||||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||||||||||||||||||||||||
| alias_out = proc.stdout.read().decode('utf-8').strip().split('\n') | ||||||||||||||||||||||||||||||||||||||||||||||
| for alias in alias_out: | ||||||||||||||||||||||||||||||||||||||||||||||
| name, value = alias.replace('alias ', '', 1).split(' ', 1) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+23
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 Error 🐛 BugAlias parsing fails on empty output. Issue Explanation
alias_out = proc.stdout.read().decode('utf-8').strip().split('\n')
for alias in alias_out:
name, value = alias.replace('alias ', '', 1).split(' ', 1)Reply if you have any questions or let me know if I missed something.
Comment on lines
+23
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 Error 🐛 BugParsing fails for alias definitions without space separators. Issue Explanation
name, value = alias.replace('alias ', '', 1).split(' ', 1)Reply if you have any questions or let me know if I missed something. |
||||||||||||||||||||||||||||||||||||||||||||||
| if name not in overridden: | ||||||||||||||||||||||||||||||||||||||||||||||
| aliases[name] = value | ||||||||||||||||||||||||||||||||||||||||||||||
| return aliases | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+23
to
28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add error handling for malformed alias lines to prevent runtime crashes. The simplified parsing logic assumes all alias lines follow the exact "alias name value" format, but lacks error handling for edge cases that could cause a Potential issues:
Apply this diff to add robust error handling: @cache('~/.config/fish/config.fish')
def _get_aliases(overridden):
aliases = {}
proc = Popen(['fish', '-ic', 'alias'], stdout=PIPE, stderr=DEVNULL)
alias_out = proc.stdout.read().decode('utf-8').strip().split('\n')
for alias in alias_out:
+ if not alias.strip() or not alias.startswith('alias '):
+ continue
+ try:
name, value = alias.replace('alias ', '', 1).split(' ', 1)
+ except ValueError:
+ # Skip malformed alias lines
+ continue
if name not in overridden:
aliases[name] = value
return aliases📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Restore edge case testing to maintain robust test coverage.
The mocked alias output was simplified to only include valid formats, removing important edge case testing that validates the robustness of the alias parsing logic.
The previous test cases likely included formats like
alias_with_equal_sign=echoandinvalid_aliasto ensure the parser could handle real-world Fish shell output variations. Removing these tests reduces coverage for potential production scenarios.Consider restoring edge case testing:
@pytest.fixture(autouse=True) def Popen(self, mocker): mock = mocker.patch('thefuck.shells.fish.Popen') mock.return_value.stdout.read.side_effect = [( b'cd\nfish_config\nfuck\nfunced\nfuncsave\ngrep\nhistory\nll\nls\n' b'man\nmath\npopd\npushd\nruby'), - b'alias fish_key_reader /usr/bin/fish_key_reader\nalias g git'] + b'alias fish_key_reader /usr/bin/fish_key_reader\nalias g git\n' + b'alias_with_equal_sign=echo\ninvalid_alias\n'] return mockThen add a separate test to verify that malformed aliases are properly handled without crashing.
📝 Committable suggestion
🤖 Prompt for AI Agents