-
Notifications
You must be signed in to change notification settings - Fork 173
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
Added 'did you mean' suggestions middleware #372
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9aaf9a7
Added 'did you mean' suggestions middleware
Cawllec 95f3501
Added tests
Cawllec 399c2d4
Spelling and references
Cawllec ec23520
Changed how the tabs display
Cawllec 0a692c1
Collate suggestion data on error tab
kattrali 26e173d
Merge branch 'v5' into did-you-mean
kattrali File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module Bugsnag::Middleware | ||
class SuggestionData | ||
|
||
CAPTURE_REGEX = /Did you mean\?([\s\S]+)$/ | ||
DELIMITER = "\n" | ||
|
||
def initialize(bugsnag) | ||
@bugsnag = bugsnag | ||
end | ||
|
||
def call(report) | ||
matches = [] | ||
report.raw_exceptions.each do |exception| | ||
match = CAPTURE_REGEX.match(exception.message) | ||
next unless match | ||
|
||
suggestions = match.captures[0].split(DELIMITER) | ||
matches.concat suggestions.map{ |suggestion| suggestion.strip } | ||
end | ||
|
||
if matches.size == 1 | ||
report.add_tab(:"did you mean", {:suggestion => matches.first}) | ||
elsif matches.size > 1 | ||
report.add_tab(:"did you mean", {:suggestions => matches}) | ||
end | ||
|
||
@bugsnag.call(report) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Commonly in other notifiers we use an error tab i believe to generically have information about the error? Having a tab with one entry in it doesnt seem like something we would want to do long term
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.
That's a good idea. We could use "Error" as the tab name, in case there is other error-specific items to add later.
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.
As an idea I just had - its where the bugsnag_meta_data attached to the error could go?
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.
Would that risk making the 'custom' tab redundant? It might be useful creating an 'error' tab and renaming the 'custom' tab to separate error generated vs user generated
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.
I dont understand the concern? The custom tab only shows up if someone puts something there. I was just saying if you attach metadata to the error and there was an error tab I would expect it to show up there.
Not a big deal though.
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.
@Cawllec The custom tab is where metadata is collated if it does not conform to the expected format (e.g., not nested so that there is a tab name and a key name, like if you use
report.add_tab(:error, "foo")
). Its a bit out of scope of this changeset, but I think I see what you mean. Let's use:error
as the tab name here though, and then we could separately use it as the tab forbugsnag_meta_data
in a later feature.