Skip to content
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

add some global error handling options #8

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions app/jobs/slackathon/slack_command_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,21 @@ def perform(name, type, params)

say(url, body)
rescue => e
say(url, {
response_type: "ephemeral",
text: <<~TEXT
:mac_bomb: Darn - that slash command (#{name.underscore.gsub("_command", "")}) didn't work
```
#{e.class}: #{e.message}
#{e.backtrace.take(5).map { |line| line.indent(4) }.join("\n")}
...
```
TEXT
})

raise e
if Slackathon.report_errors?
Copy link
Member

Choose a reason for hiding this comment

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

What about echo_errors?

say(url, {
response_type: "ephemeral",
text: <<~TEXT
:mac_bomb: Darn - that slash command (#{name.underscore.gsub("_command", "")}) didn't work
```
#{e.class}: #{e.message}
#{e.backtrace.take(5).map { |line| line.indent(4) }.join("\n")}
...
```
TEXT
})
end

raise e if Slackathon.raise_errors?
end

private
Expand Down
17 changes: 17 additions & 0 deletions lib/slackathon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,21 @@ def self.queue
def self.queue=(queue)
@queue = queue
end

def self.report_errors?
@report_errors = true unless defined?(@report_errors)
Copy link
Member

Choose a reason for hiding this comment

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

We should probably just change this file to eagerly assign the default values right after we define the setter. Do you think that would break anything?

!!@report_errors
end

def self.report_errors=(val)
@report_errors = val
end

def self.raise_errors?
!!@raise_errors
end

def self.raise_errors=(val)
@raise_errors = val
end
end