Skip to content

BazaRb raises RuntimeError for everything — no custom error hierarchy for callers #362

Description

@VasilevNStas

BazaRb raises RuntimeError for everything — no custom error hierarchy for callers

Severity: MEDIUM (Design/API)

Location

lib/baza-rb.rb — everywhere:

raise 'Invalid parameter'            # RuntimeError
raise(BadCompression, '...')         # BadCompression < RuntimeError
raise(Error, '...')                  # Error < RuntimeError (rarely used)

Problem

Callers cannot distinguish error types:

begin
  baza.push(...)
rescue => e
  # Is this a validation error? Network error? Server error?
  # Must parse e.message, which may change
end

Recommended fix

Introduce an error hierarchy:

module BazaRb
  class Error < StandardError; end
  class ValidationError < Error; end
  class InvalidName < ValidationError; end
  class InvalidAmount < ValidationError; end
  class ApiError < Error; end
  class BadCompression < Error; end
  class Unauthorized < ApiError; end
  class NotFound < ApiError; end
  class TooManyRequests < ApiError; end
  class RetryExhausted < Error; end
end

This allows callers to catch specific error groups without parsing messages.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions