SonarSource Rules
  • Products

    In-IDE

    Code Quality and Security in your IDE with SonarQube Ide

    IDE extension that lets you fix coding issues before they exist!

    Discover SonarQube for IDE

    SaaS

    Code Quality and Security in the cloud with SonarQube Cloud

    Setup is effortless and analysis is automatic for most languages

    Discover SonarQube Cloud

    Self-Hosted

    Code Quality and Security Self-Hosted with SonarQube Server

    Fast, accurate analysis; enterprise scalability

    Discover SonarQube Server
  • SecretsSecrets
  • ABAPABAP
  • AnsibleAnsible
  • ApexApex
  • AzureResourceManagerAzureResourceManager
  • CC
  • C#C#
  • C++C++
  • CloudFormationCloudFormation
  • COBOLCOBOL
  • CSSCSS
  • DartDart
  • DockerDocker
  • FlexFlex
  • GitHub ActionsGitHub Actions
  • GoGo
  • HTMLHTML
  • JavaJava
  • JavaScriptJavaScript
  • JSONJSON
  • JCLJCL
  • KotlinKotlin
  • KubernetesKubernetes
  • Objective CObjective C
  • PHPPHP
  • PL/IPL/I
  • PL/SQLPL/SQL
  • PythonPython
  • RPGRPG
  • RubyRuby
  • RustRust
  • ScalaScala
  • ShellShell
  • SwiftSwift
  • TerraformTerraform
  • TextText
  • TypeScriptTypeScript
  • T-SQLT-SQL
  • VB.NETVB.NET
  • VB6VB6
  • XMLXML
  • YAMLYAML
Ruby

Ruby static code analysis

Unique rules to find Bugs, Security Hotspots, and Code Smells in your RUBY code

  • All rules 75
  • Bug17
  • Security Hotspot2
  • Code Smell56
Filtered: 2 rules found
exception
    Impact
      Clean code attribute
        1. Bare rescue clauses should specify exception types

           Code Smell
        2. Exception classes should be used instead of raising generic strings

           Code Smell

        Exception classes should be used instead of raising generic strings

        intentionality - complete
        maintainability
        Code Smell
        • exception
        • ruby

        This rule raises an issue when raise is called with a string literal instead of a specific exception class.

        Why is this an issue?

        How can I fix it?

        More Info

        Raising generic string messages as exceptions creates several problems that make code harder to maintain and test.

        When you use raise "message", Ruby automatically wraps the string in a RuntimeError. This means all your different error conditions become indistinguishable RuntimeError exceptions. Your calling code cannot handle different types of errors appropriately.

        For example, you might want to retry on network errors but immediately fail on validation errors. With generic string exceptions, this becomes impossible because both errors look the same to exception handlers.

        Testing also becomes problematic. Your tests must catch the generic RuntimeError class, which means they cannot verify that the right type of error occurred. This makes tests less precise and more likely to pass when they should fail.

        Using specific exception classes solves these problems. Each error condition gets its own class, making error handling more precise. Tests can verify the exact type of exception, improving test reliability. Code becomes more self-documenting because exception names clearly indicate what went wrong.

        What is the potential impact?

        Using generic string exceptions reduces code maintainability and makes error handling imprecise. Tests become less reliable because they cannot distinguish between different error conditions. This can lead to bugs being missed in testing and inappropriate error handling in production code.

          Available In:
        • SonarQube CloudDetect issues in your GitHub, Azure DevOps Services, Bitbucket Cloud, GitLab repositories

        © 2008-2025 SonarSource SA. All rights reserved.

        Privacy Policy | Cookie Policy | Terms of Use