Skip to content

Gracefully handle incorrect command aliases - #1059

Merged
st0012 merged 2 commits into
masterfrom
fix-#992
Jan 10, 2025
Merged

st0012 merged 2 commits into
masterfrom
fix-#992

Conversation

@st0012

@st0012 st0012 commented Jan 3, 2025

Copy link
Copy Markdown
Member

Even if the aliased target is a helper method or does not exist, IRB should not crash.

This commit warns users in such cases and treat the input as normal expression.

Fixes #992

Even if the aliased target is a helper method or does not exist, IRB
should not crash.

This commit warns users in such cases and treat the input as normal expression.
@st0012 st0012 added the bug Something isn't working label Jan 3, 2025
@st0012 st0012 self-assigned this Jan 3, 2025
Comment thread lib/irb.rb Outdated
Comment thread lib/irb/context.rb
message = <<~MESSAGE
Using command alias `#{command}` for helper method `#{aliased_name}` is not supported.
Please check the value of `IRB.conf[:COMMAND_ALIASES]`.
MESSAGE

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about moving this message generating part into IncorrectAlias and just return Statement::IncorrectAlias.new(aliased_name) here

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But that means we'll be querying registered helper methods from a Statement class, which IMO is a bad coupling. I think this type of interaction is better happen inside Context or Irb?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. 👍

@st0012
st0012 merged commit 9fc14eb into master Jan 10, 2025
@st0012
st0012 deleted the fix-#992 branch January 10, 2025 21:29
matzbot pushed a commit to ruby/ruby that referenced this pull request Jan 10, 2025
(ruby/irb#1059)

* Gracefully handle incorrect command aliases

Even if the aliased target is a helper method or does not exist, IRB
should not crash.

This commit warns users in such cases and treat the input as normal expression.

* Streamline command parsing and introduce warnings for incorrect command aliases

ruby/irb@9fc14eb74b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

next alias crashing

2 participants