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 #single_line_exceptions feature. #51

Merged
merged 4 commits into from
Jan 23, 2014
Merged

Conversation

asenchi
Copy link
Owner

@asenchi asenchi commented Jan 23, 2014

This adds a new feature for managing exception data in generated log messages. Default behavior is to generate a log message for each line of the backtrace, the result of which could be many lines for a single exception. To cut down on duplication and data transport this generates a single log message for the exception, joining all backtrace lines by '\n'.

Before

now="2014-01-23T13:22:32Z" app=scrolls deploy=nil at=exception class=NoMethodError message="undefined method `empty?' for nil:NilClass" exception_id=70161806013660
now="2014-01-23T13:22:32Z" app=scrolls deploy=nil at=exception class="undefined method `empty?' for nil:NilClass" exception_id=70161806013660 site="./test.rb:16:in <main>"

After

now="2014-01-23T13:22:59Z" app=scrolls deploy=nil at=exception class=NoMethodError message="undefined method `empty?' for nil:NilClass" exception_id=70116515914640

@asenchi
Copy link
Owner Author

asenchi commented Jan 23, 2014

I need to find a method for generating a longer exception, both for examples above and tests. Anyone have ideas?

@jasonrudolph
Copy link
Contributor

I need to find a method for generating a longer exception, both for examples above and tests.

Here's one option to consider: https://gist.github.com/jasonrudolph/584058a67b64d89e9957

There might be a better way to accomplish this, but that approach would probably work for testing purposes.

You mentioned that you're also hoping to generate long exceptions for use in examples. The approach above will probably not work for that purpose. It would produce some pretty boring examples. ;-)

@asenchi
Copy link
Owner Author

asenchi commented Jan 23, 2014

Oh, nice, I'll work that up this afternoon.

@asenchi
Copy link
Owner Author

asenchi commented Jan 23, 2014

Alright, fixed this up, need to work on tests yet:

Before

now="2014-01-23T19:31:08Z" app=scrolls deploy=nil at=exception class=RuntimeError message=Boom! exception_id=70181716367520
now="2014-01-23T19:31:08Z" app=scrolls deploy=nil at=exception class=RuntimeError message=Boom! exception_id=70181716367520 site="./test.rb:11:in raise_error_with_at_least_n_backtrace_lines"
now="2014-01-23T19:31:08Z" app=scrolls deploy=nil at=exception class=RuntimeError message=Boom! exception_id=70181716367520 site="./test.rb:12:in raise_error_with_at_least_n_backtrace_lines"
now="2014-01-23T19:31:08Z" app=scrolls deploy=nil at=exception class=RuntimeError message=Boom! exception_id=70181716367520 site="./test.rb:12:in raise_error_with_at_least_n_backtrace_lines"
now="2014-01-23T19:31:08Z" app=scrolls deploy=nil at=exception class=RuntimeError message=Boom! exception_id=70181716367520 site="./test.rb:12:in raise_error_with_at_least_n_backtrace_lines"
now="2014-01-23T19:31:08Z" app=scrolls deploy=nil at=exception class=RuntimeError message=Boom! exception_id=70181716367520 site="./test.rb:12:in raise_error_with_at_least_n_backtrace_lines"
now="2014-01-23T19:31:08Z" app=scrolls deploy=nil at=exception class=RuntimeError message=Boom! exception_id=70181716367520 site="./test.rb:12:in raise_error_with_at_least_n_backtrace_lines"
now="2014-01-23T19:31:08Z" app=scrolls deploy=nil at=exception class=RuntimeError message=Boom! exception_id=70181716367520 site="./test.rb:12:in raise_error_with_at_least_n_backtrace_lines"
now="2014-01-23T19:31:08Z" app=scrolls deploy=nil at=exception class=RuntimeError message=Boom! exception_id=70181716367520 site="./test.rb:12:in raise_error_with_at_least_n_backtrace_lines"
now="2014-01-23T19:31:08Z" app=scrolls deploy=nil at=exception class=RuntimeError message=Boom! exception_id=70181716367520 site="./test.rb:12:in raise_error_with_at_least_n_backtrace_lines"
now="2014-01-23T19:31:08Z" app=scrolls deploy=nil at=exception class=RuntimeError message=Boom! exception_id=70181716367520 site="./test.rb:12:in raise_error_with_at_least_n_backtrace_lines"
now="2014-01-23T19:31:08Z" app=scrolls deploy=nil at=exception class=RuntimeError message=Boom! exception_id=70181716367520 site="./test.rb:12:in raise_error_with_at_least_n_backtrace_lines"
now="2014-01-23T19:31:08Z" app=scrolls deploy=nil at=exception class=RuntimeError message=Boom! exception_id=70181716367520 site="./test.rb:12:in raise_error_with_at_least_n_backtrace_lines"
now="2014-01-23T19:31:08Z" app=scrolls deploy=nil at=exception class=RuntimeError message=Boom! exception_id=70181716367520 site="./test.rb:12:in raise_error_with_at_least_n_backtrace_lines"
now="2014-01-23T19:31:08Z" app=scrolls deploy=nil at=exception class=RuntimeError message=Boom! exception_id=70181716367520 site="./test.rb:12:in raise_error_with_at_least_n_backtrace_lines"
now="2014-01-23T19:31:08Z" app=scrolls deploy=nil at=exception class=RuntimeError message=Boom! exception_id=70181716367520 site="./test.rb:12:in raise_error_with_at_least_n_backtrace_lines"
now="2014-01-23T19:31:08Z" app=scrolls deploy=nil at=exception class=RuntimeError message=Boom! exception_id=70181716367520 site="./test.rb:12:in raise_error_with_at_least_n_backtrace_lines"
now="2014-01-23T19:31:08Z" app=scrolls deploy=nil at=exception class=RuntimeError message=Boom! exception_id=70181716367520 site="./test.rb:12:in raise_error_with_at_least_n_backtrace_lines"
now="2014-01-23T19:31:08Z" app=scrolls deploy=nil at=exception class=RuntimeError message=Boom! exception_id=70181716367520 site="./test.rb:12:in raise_error_with_at_least_n_backtrace_lines"
now="2014-01-23T19:31:08Z" app=scrolls deploy=nil at=exception class=RuntimeError message=Boom! exception_id=70181716367520 site="./test.rb:12:in raise_error_with_at_least_n_backtrace_lines"
now="2014-01-23T19:31:08Z" app=scrolls deploy=nil at=exception class=RuntimeError message=Boom! exception_id=70181716367520 site="./test.rb:12:in raise_error_with_at_least_n_backtrace_lines"
now="2014-01-23T19:31:08Z" app=scrolls deploy=nil at=exception class=RuntimeError message=Boom! exception_id=70181716367520 site="./test.rb:16:in <main>"

Scrolls.single_line_exceptions = true

now="2014-01-23T19:31:02Z" app=scrolls deploy=nil at=exception class=RuntimeError message=Boom! exception_id=70171943639240 site="./test.rb:11:in raise_error_with_at_least_n_backtrace_lines\\n./test.rb:12:in raise_error_with_at_least_n_backtrace_lines\\n./test.rb:12:in raise_error_with_at_least_n_backtrace_lines\\n./test.rb:12:in raise_error_with_at_least_n_backtrace_lines\\n./test.rb:12:in raise_error_with_at_least_n_backtrace_lines\\n./test.rb:12:in raise_error_with_at_least_n_backtrace_lines\\n./test.rb:12:in raise_error_with_at_least_n_backtrace_lines\\n./test.rb:12:in raise_error_with_at_least_n_backtrace_lines\\n./test.rb:12:in raise_error_with_at_least_n_backtrace_lines\\n./test.rb:12:in raise_error_with_at_least_n_backtrace_lines\\n./test.rb:12:in raise_error_with_at_least_n_backtrace_lines\\n./test.rb:12:in raise_error_with_at_least_n_backtrace_lines\\n./test.rb:12:in raise_error_with_at_least_n_backtrace_lines\\n./test.rb:12:in raise_error_with_at_least_n_backtrace_lines\\n./test.rb:12:in raise_error_with_at_least_n_backtrace_lines\\n./test.rb:12:in raise_error_with_at_least_n_backtrace_lines\\n./test.rb:12:in raise_error_with_at_least_n_backtrace_lines\\n./test.rb:12:in raise_error_with_at_least_n_backtrace_lines\\n./test.rb:12:in raise_error_with_at_least_n_backtrace_lines\\n./test.rb:12:in raise_error_with_at_least_n_backtrace_lines\\n./test.rb:16:in <main>"

# Scrolls.single_line_exceptions
# => true
#
def single_line_exceptions
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this returns a Boolean, I recommend renaming it to single_line_exceptions?.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Hmm, we haven't practiced that style, but it's probably a good idea to start.

@asenchi
Copy link
Owner Author

asenchi commented Jan 23, 2014

Alright, we've got tests. Going to ship a new version with this.

asenchi added a commit that referenced this pull request Jan 23, 2014
Add #single_line_exceptions feature.
@asenchi asenchi merged commit 7a08a5d into master Jan 23, 2014
@asenchi asenchi deleted the single-line-exceptions branch January 23, 2014 20:49
asenchi added a commit that referenced this pull request Jan 23, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants