### Run Solid Errors Rails Installer
Source: https://github.com/fractaledmind/solid_errors/blob/main/README.md
Executes the Solid Errors generator to set up necessary files, including `db/errors_schema.rb`, for database integration.
```bash
rails generate solid_errors:install
```
--------------------------------
### Ruby: Configure Solid Errors for Separate Primary/Replica Database
Source: https://github.com/fractaledmind/solid_errors/blob/main/README.md
This example demonstrates configuring `config.solid_errors.connects_to` to utilize a separate primary/replica database pair for Solid Errors. This setup is suitable for applications requiring read/write separation for their error logs.
```ruby
# Use a separate primary/replica pair for Solid Errors
config.solid_errors.connects_to = { database: { writing: :solid_errors_primary, reading: :solid_errors_replica } }
```
--------------------------------
### Run Solid Errors Database Migration
Source: https://github.com/fractaledmind/solid_errors/blob/main/UPGRADE.md
Executes the pending database migrations for the specified errors database, applying the schema changes defined in the `UpgradeSolidErrors` migration.
```bash
rails db:migrate:{name_of_errors_database}
```
--------------------------------
### Install Solid Errors Gem Manually
Source: https://github.com/fractaledmind/solid_errors/blob/main/README.md
Installs the Solid Errors gem globally or into your Ruby environment if Bundler is not used for dependency management.
```bash
gem install solid_errors
```
--------------------------------
### Install Solid Errors Gem with Bundler
Source: https://github.com/fractaledmind/solid_errors/blob/main/README.md
Adds the Solid Errors gem to your application's Gemfile using Bundler, managing dependencies automatically.
```bash
bundle add solid_errors
```
--------------------------------
### Generate Solid Errors Upgrade Migration
Source: https://github.com/fractaledmind/solid_errors/blob/main/UPGRADE.md
Generates a new Rails migration file for the specified errors database, preparing for schema changes required by Solid Errors 0.4.0.
```bash
rails generate migration UpgradeSolidErrors --database {name_of_errors_database}
```
--------------------------------
### Solid Errors Development and Release Commands
Source: https://github.com/fractaledmind/solid_errors/blob/main/README.md
This snippet provides a series of bash commands for setting up the Solid Errors development environment, running tests, interacting with the console, migrating the database, installing the gem locally, and releasing new versions to RubyGems.
```bash
bin/setup
rake test
bin/console
rake db:migrate
bundle exec rake install
bundle exec rake release
```
--------------------------------
### Generate Migration for Non-Nullable Fingerprint
Source: https://github.com/fractaledmind/solid_errors/blob/main/UPGRADE.md
Generates a new Rails migration file to mark the `fingerprint` column in the `solid_errors` table as non-nullable, ensuring data integrity after all existing errors have been fingerprinted.
```bash
rails generate migration SolidErrorFingerprintNonNullable --database {name_of_errors_database}
```
--------------------------------
### Define Solid Errors Fingerprint Non-Nullable Migration
Source: https://github.com/fractaledmind/solid_errors/blob/main/UPGRADE.md
Defines the `change` method for the `SolidErrorFingerprintNonNullable` migration, setting the `fingerprint` column in the `solid_errors` table to be non-nullable.
```ruby
class SolidErrorFingerprintNonNullable < ActiveRecord::Migration[7.1]
def change
change_column_null :solid_errors, :fingerprint, false
end
}
```
--------------------------------
### Fingerprint Existing Solid Errors Data
Source: https://github.com/fractaledmind/solid_errors/blob/main/UPGRADE.md
Ruby script to backfill the `fingerprint` column for existing `SolidErrors::Error` records that do not yet have one. It calculates a SHA256 hash from key error attributes and updates the records.
```ruby
SolidErrors::Error.where(fingerprint: nil).find_each do |error|
error_attributes = error.attributes.slice('exception_class', 'message', 'severity', 'source')
fingerprint = Digest::SHA256.hexdigest(error_attributes.values.join)
error.update_attribute(:fingerprint, fingerprint)
end
```
--------------------------------
### Example of Overwriting Solid Errors Application Layout
Source: https://github.com/fractaledmind/solid_errors/blob/main/README.md
This ERB snippet demonstrates how to customize the `application.html.erb` layout for Solid Errors. It shows a basic HTML structure with placeholders for content and conditional display of flash messages, excluding the default footer and auto-disappearing flashes.
```erb
<% if notice.present? %>
<%= notice %>
<% end %>
<% if alert.present? %>
<%= alert %>
<% end %>
```
--------------------------------
### Ruby: Report Errors with Custom Options using Rails.error.handle
Source: https://github.com/fractaledmind/solid_errors/blob/main/README.md
This example demonstrates how to pass custom options like `context` and `severity` to `Rails.error.handle`. These options allow you to enrich the error report with specific details, such as a user ID or a custom severity level.
```ruby
Rails.error.handle(context: { user_id: user.id }, severity: :info) do
# ...
end
```
--------------------------------
### Define Solid Errors 0.4.0 Schema Migration
Source: https://github.com/fractaledmind/solid_errors/blob/main/UPGRADE.md
Defines the `up` and `down` methods for the `UpgradeSolidErrors` migration. It modifies `solid_errors` table columns to `text` type, adds a `fingerprint` column, and updates unique indexes to use the new `fingerprint`.
```ruby
class UpgradeSolidErrors < ActiveRecord::Migration[7.1]
def up
change_column :solid_errors, :exception_class, :text, null: false, limit: nil
change_column :solid_errors, :message, :text, null: false, limit: nil
change_column :solid_errors, :severity, :text, null: false, limit: nil
change_column :solid_errors, :source, :text, null: true, limit: nil
add_column :solid_errors, :fingerprint, :string, limit: 64
add_index :solid_errors, :fingerprint, unique: true
remove_index :solid_errors, [:exception_class, :message, :severity, :source], unique: true
end
def down
change_column :solid_errors, :exception_class, :string, null: false, limit: 200
change_column :solid_errors, :message, :string, null: false, limit: nil
change_column :solid_errors, :severity, :string, null: false, limit: 25
change_column :solid_errors, :source, :string, null: true, limit: nil
remove_index :solid_errors, [:fingerprint], unique: true
remove_column :solid_errors, :fingerprint, :string, limit: 64
add_index :solid_errors, [:exception_class, :message, :severity, :source], unique: true
end
}
```
--------------------------------
### Screen Reader Only Utility Class (Incomplete)
Source: https://github.com/fractaledmind/solid_errors/blob/main/app/views/layouts/solid_errors/_style.html
Starts the definition for a `.sr-only` class, typically used to visually hide elements while keeping them accessible to screen readers. The provided snippet is incomplete.
```CSS
.sr-only{ positi
```
--------------------------------
### Configure MySQL/PostgreSQL/Trilogy Database for Solid Errors
Source: https://github.com/fractaledmind/solid_errors/blob/main/README.md
Configures `config/database.yml` for MySQL, PostgreSQL, or Trilogy, setting up a dedicated `errors` database that inherits primary database settings.
```yaml
production:
primary: &primary_production
<<: *default
database: app_production
username: app
password: <%= ENV["APP_DATABASE_PASSWORD"] %>
errors:
<<: *primary_production
database: app_production_errors
migrations_paths: db/errors_migrate
```
--------------------------------
### Configure Solid Errors Authentication with Environment Variables
Source: https://github.com/fractaledmind/solid_errors/blob/main/README.md
This Ruby snippet demonstrates how to set the username and password for Solid Errors basic HTTP authentication using environment variables. These variables are checked by Solid Errors to enable dashboard security.
```ruby
ENV["SOLIDERRORS_USERNAME"] = "frodo"
ENV["SOLIDERRORS_PASSWORD"] = "ikeptmysecrets"
```
--------------------------------
### Configure SQLite Database for Solid Errors
Source: https://github.com/fractaledmind/solid_errors/blob/main/README.md
Configures `config/database.yml` for a SQLite database, defining a separate `errors` database for Solid Errors with its own migration path.
```yaml
production:
primary:
<<: *default
database: storage/production.sqlite3
errors:
<<: *default
database: storage/production_errors.sqlite3
migrations_paths: db/errors_migrate
```
--------------------------------
### Solid Errors Default View Directory Structure
Source: https://github.com/fractaledmind/solid_errors/blob/main/README.md
This snippet illustrates the default file structure for views within the Solid Errors gem, showing the paths where layout, error, and occurrence templates are located. Users can replicate this structure in their application to override default views.
```bash
app/views/
├── layouts
│ └── solid_errors
│ ├── _style.html
│ └── application.html.erb
└── solid_errors
├── error_mailer
│ ├── error_occurred.html.erb
│ └── error_occurred.text.erb
├── errors
│ ├── _actions.html.erb
│ ├── _error.html.erb
│ ├── _row.html.erb
│ ├── index.html.erb
│ └── show.html.erb
└── occurrences
├── _collection.html.erb
└── _occurrence.html.erb
```
--------------------------------
### APIDOC: Solid Errors Configuration Options
Source: https://github.com/fractaledmind/solid_errors/blob/main/README.md
Solid Errors can be configured via the Rails configuration object under the `solid_errors` key. These options control various aspects, including database connection, authentication, email notifications, and record destruction.
```APIDOC
Solid Errors Configuration Options (config.solid_errors):
- connects_to: Hash
Description: The database configuration to use for the Solid Errors database. See Database Configuration.
- username: String
Description: The username for HTTP authentication.
- password: String
Description: The password for HTTP authentication.
- sends_email: Boolean
Description: Whether to send emails when an error occurs.
- email_from: String
Description: The email address to send notifications from.
- email_to: String or Array