Prevent recursion when invoking AI
This can result in stack overflow errors for missing commands. https://fizzy.37signals.com/5986089/collections/7/cards/1135 Follow up to https://github.com/basecamp/fizzy/pull/766
This commit is contained in:
@@ -3,8 +3,9 @@ class Command::Parser
|
||||
|
||||
delegate :user, :cards, :filter, :script_name, to: :context
|
||||
|
||||
def initialize(context)
|
||||
def initialize(context, fall_back_to_ai: true)
|
||||
@context = context
|
||||
@fall_back_to_ai = fall_back_to_ai
|
||||
end
|
||||
|
||||
def parse(string)
|
||||
@@ -17,6 +18,10 @@ class Command::Parser
|
||||
end
|
||||
|
||||
private
|
||||
def fall_back_to_ai?
|
||||
@fall_back_to_ai
|
||||
end
|
||||
|
||||
def as_plain_text(string)
|
||||
ActionText::Content.new(string).to_plain_text
|
||||
end
|
||||
@@ -100,7 +105,7 @@ class Command::Parser
|
||||
elsif card = single_card_from(string)
|
||||
Command::GoToCard.new(card_id: card.id)
|
||||
else
|
||||
Command::Ai::Parser.new(context).parse(string)
|
||||
parse_with_fallback(string)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -114,4 +119,12 @@ class Command::Parser
|
||||
def single_card_from(string)
|
||||
user.accessible_cards.find_by_id(string)
|
||||
end
|
||||
|
||||
def parse_with_fallback(string)
|
||||
if fall_back_to_ai?
|
||||
Command::Ai::Parser.new(context).parse(string)
|
||||
else
|
||||
Command::Search.new(terms: string)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user