Skip to content

Commit

Permalink
Use sentence case for all standard library exceptions (#13400)
Browse files Browse the repository at this point in the history
  • Loading branch information
HertzDevil committed May 3, 2023
1 parent 6a9b3ec commit b65280a
Show file tree
Hide file tree
Showing 50 changed files with 91 additions and 91 deletions.
2 changes: 1 addition & 1 deletion samples/meteor.cr
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def get_id(m : UInt64)
10.times do |id|
return id.to_u8 if bm(m, id + 50) != 0
end
raise "does not have a valid identifier"
raise "Does not have a valid identifier"
end

def to_utf8(raw_sol)
Expand Down
2 changes: 1 addition & 1 deletion samples/pretty_json.cr
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class PrettyPrinter
when .eof?
# We are done
when .end_array?, .end_object?
raise "Bug: shouldn't happen"
raise "Bug: Shouldn't happen"
end
end

Expand Down
2 changes: 1 addition & 1 deletion samples/sdl/fire.cr
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ class RainbowColorPattern < ColorPattern
end

def interpolate(life)
raise "shouldn't reach here"
raise "Shouldn't reach here"
end
end

Expand Down
2 changes: 1 addition & 1 deletion scripts/generate_grapheme_break_specs.cr
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ File.open(path, "w") do |file|
end
grapheme = String::Builder.new
when "×"
else raise "unexpected operator #{operator.inspect}"
else raise "Unexpected operator #{operator.inspect}"
end
grapheme << char
end
Expand Down
2 changes: 1 addition & 1 deletion scripts/generate_unicode_data.cr
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ canonical_combining_classes.sort_by! &.low
canonical_decompositions = entries.compact_map do |entry|
next unless entry.decomposition_type.canonical?
mapping = entry.decomposition_mapping.not_nil!
raise "BUG: mapping longer than 2 codepoints" unless mapping.size <= 2
raise "BUG: Mapping longer than 2 codepoints" unless mapping.size <= 2
{entry.codepoint, mapping[0], mapping[1]? || 0}
end

Expand Down
8 changes: 4 additions & 4 deletions spec/compiler/codegen/cast_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe "Code gen: cast" do
a.as(Char)
false
rescue ex
ex.message.not_nil!.includes?("cast from Int32 to Char failed") && (ex.class == TypeCastError)
ex.message.not_nil!.includes?("Cast from Int32 to Char failed") && (ex.class == TypeCastError)
end
)).to_b.should be_true
end
Expand All @@ -72,7 +72,7 @@ describe "Code gen: cast" do
a.as(Float64 | Char)
false
rescue ex
ex.message.not_nil!.includes?("cast from Int32 to (Char | Float64) failed") && (ex.class == TypeCastError)
ex.message.not_nil!.includes?("Cast from Int32 to (Char | Float64) failed") && (ex.class == TypeCastError)
end
)).to_b.should be_true
end
Expand Down Expand Up @@ -120,7 +120,7 @@ describe "Code gen: cast" do
a.as(CastSpecBaz)
false
rescue ex
ex.message.not_nil!.includes?("cast from CastSpecBar to CastSpecBaz failed") && (ex.class == TypeCastError)
ex.message.not_nil!.includes?("Cast from CastSpecBar to CastSpecBaz failed") && (ex.class == TypeCastError)
end
)).to_b.should be_true
end
Expand Down Expand Up @@ -187,7 +187,7 @@ describe "Code gen: cast" do
a.as(Nil)
false
rescue ex
ex.message.not_nil!.includes?("cast from Reference to Nil failed") && (ex.class == TypeCastError)
ex.message.not_nil!.includes?("Cast from Reference to Nil failed") && (ex.class == TypeCastError)
end
)).to_b.should be_true
end
Expand Down
2 changes: 1 addition & 1 deletion spec/compiler/interpreter/casts_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ describe Crystal::Repl::Interpreter do
end

it "raises when as fails" do
interpret(<<-CRYSTAL, prelude: "prelude").to_s.should contain("cast from Int32 to Char failed")
interpret(<<-CRYSTAL, prelude: "prelude").to_s.should contain("Cast from Int32 to Char failed")
x = 1 || 'a'
begin
x.as(Char)
Expand Down
8 changes: 4 additions & 4 deletions spec/std/ini_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ describe "INI" do
describe "parse" do
context "from String" do
it "fails on malformed section" do
expect_raises(INI::ParseException, "unterminated section") do
expect_raises(INI::ParseException, "Unterminated section") do
INI.parse("[section")
end
end

it "fails on data after section" do
expect_raises(INI::ParseException, "data after section") do
expect_raises(INI::ParseException, "Data after section") do
INI.parse("[section] foo ")
end
end

it "fails on malformed declaration" do
expect_raises(INI::ParseException, "expected declaration") do
expect_raises(INI::ParseException, "Expected declaration") do
INI.parse("foobar")
end

expect_raises(INI::ParseException, "expected declaration") do
expect_raises(INI::ParseException, "Expected declaration") do
INI.parse("foo: bar")
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/std/named_tuple_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe "NamedTuple" do
NamedTuple(foo: Int32, bar: Int32).from({:foo => 1, :baz => 2})
end

expect_raises(TypeCastError, /cast from String to Int32 failed/) do
expect_raises(TypeCastError, /[Cc]ast from String to Int32 failed/) do
NamedTuple(foo: Int32, bar: Int32).from({:foo => 1, :bar => "foo"})
end
end
Expand All @@ -63,7 +63,7 @@ describe "NamedTuple" do
{foo: Int32, bar: Int32}.from({:foo => 1, :baz => 2})
end

expect_raises(TypeCastError, /cast from String to Int32 failed/) do
expect_raises(TypeCastError, /[Cc]ast from String to Int32 failed/) do
{foo: Int32, bar: Int32}.from({:foo => 1, :bar => "foo"})
end

Expand Down
4 changes: 2 additions & 2 deletions spec/std/spec_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@ describe "Spec matchers" do

it "detects a nesting `it`" do
ex = expect_raises(Spec::NestingSpecError) { it { } }
ex.message.should eq "can't nest `it` or `pending`"
ex.message.should eq "Can't nest `it` or `pending`"
ex.file.should eq __FILE__
end

it "detects a nesting `pending`" do
ex = expect_raises(Spec::NestingSpecError) { pending }
ex.message.should eq "can't nest `it` or `pending`"
ex.message.should eq "Can't nest `it` or `pending`"
ex.file.should eq __FILE__
end

Expand Down
4 changes: 2 additions & 2 deletions spec/std/tuple_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ describe "Tuple" do
Tuple(Int32).from([1, 2])
end

expect_raises(TypeCastError, /cast from String to Int32 failed/) do
expect_raises(TypeCastError, /[Cc]ast from String to Int32 failed/) do
Tuple(Int32, String).from(["foo", 1])
end
end
Expand All @@ -239,7 +239,7 @@ describe "Tuple" do
{Int32}.from([1, 2])
end

expect_raises(TypeCastError, /cast from String to Int32 failed/) do
expect_raises(TypeCastError, /[Cc]ast from String to Int32 failed/) do
{Int32, String}.from(["foo", 1])
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/support/fibers.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ def wait_until_blocked(f : Fiber, timeout = 5.seconds)

until f.resumable?
Fiber.yield
raise "fiber failed to block within #{timeout}" if (Time.monotonic - now) > timeout
raise "Fiber failed to block within #{timeout}" if (Time.monotonic - now) > timeout
end
end

def wait_until_finished(f : Fiber, timeout = 5.seconds)
now = Time.monotonic
until f.dead?
Fiber.yield
raise "fiber failed to finish within #{timeout}" if (Time.monotonic - now) > timeout
raise "Fiber failed to finish within #{timeout}" if (Time.monotonic - now) > timeout
end
end
8 changes: 4 additions & 4 deletions src/array.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1621,7 +1621,7 @@ class Array(T)
# Raises `ArgumentError` if for any two elements the block returns `nil`.
def sort(&block : T, T -> U) : Array(T) forall U
{% unless U <= Int32? %}
{% raise "expected block to return Int32 or Nil, not #{U}" %}
{% raise "Expected block to return Int32 or Nil, not #{U}" %}
{% end %}

dup.sort! &block
Expand All @@ -1643,7 +1643,7 @@ class Array(T)
# Raises `ArgumentError` if for any two elements the block returns `nil`.
def unstable_sort(&block : T, T -> U) : Array(T) forall U
{% unless U <= Int32? %}
{% raise "expected block to return Int32 or Nil, not #{U}" %}
{% raise "Expected block to return Int32 or Nil, not #{U}" %}
{% end %}

dup.unstable_sort!(&block)
Expand All @@ -1664,7 +1664,7 @@ class Array(T)
# :inherit:
def sort!(&block : T, T -> U) : self forall U
{% unless U <= Int32? %}
{% raise "expected block to return Int32 or Nil, not #{U}" %}
{% raise "Expected block to return Int32 or Nil, not #{U}" %}
{% end %}

to_unsafe_slice.sort!(&block)
Expand All @@ -1674,7 +1674,7 @@ class Array(T)
# :inherit:
def unstable_sort!(&block : T, T -> U) : self forall U
{% unless U <= Int32? %}
{% raise "expected block to return Int32 or Nil, not #{U}" %}
{% raise "Expected block to return Int32 or Nil, not #{U}" %}
{% end %}

to_unsafe_slice.unstable_sort!(&block)
Expand Down
4 changes: 2 additions & 2 deletions src/channel.cr
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Channel(T)
# Implementor that returns `Channel::UseDefault` in `#execute`
# must redefine `#default_result`
def default_result
raise "unreachable"
raise "Unreachable"
end
end

Expand Down Expand Up @@ -406,7 +406,7 @@ class Channel(T)
# :nodoc:
def self.select(ops : Indexable(SelectAction))
i, m = select_impl(ops, false)
raise "BUG: blocking select returned not ready status" if m.is_a?(NotReady)
raise "BUG: Blocking select returned not ready status" if m.is_a?(NotReady)
return i, m
end

Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/codegen/codegen.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1380,7 +1380,7 @@ module Crystal

def type_cast_exception_call(from_type, to_type, node, var_name)
pieces = [
StringLiteral.new("cast from ").at(node),
StringLiteral.new("Cast from ").at(node),
Call.new(Var.new(var_name).at(node), "class").at(node),
StringLiteral.new(" to #{to_type} failed").at(node),
] of ASTNode
Expand Down
2 changes: 1 addition & 1 deletion src/crystal/digest/sha1.cr
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Crystal::Digest::SHA1 < ::Digest
if @length_low == 0
@length_high &+= 1
if @length_high == 0
raise ArgumentError.new "Crypto.sha1: message too long"
raise ArgumentError.new "Message too long"
end
end

Expand Down
6 changes: 3 additions & 3 deletions src/crystal/dwarf/line_numbers.cr
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ module Crystal
sequence.version = @io.read_bytes(UInt16)

if sequence.version < 2 || sequence.version > 5
raise "unknown line table version: #{sequence.version}"
raise "Unknown line table version: #{sequence.version}"
end

if sequence.version >= 5
Expand All @@ -239,14 +239,14 @@ module Crystal
end

if sequence.maximum_operations_per_instruction == 0
raise "invalid maximum operations per instruction: 0"
raise "Invalid maximum operations per instruction: 0"
end

sequence.default_is_stmt = @io.read_byte == 1
sequence.line_base = @io.read_bytes(Int8).to_i
sequence.line_range = @io.read_bytes(UInt8).to_i
if sequence.line_range == 0
raise "invalid line range: 0"
raise "Invalid line range: 0"
end

sequence.opcode_base = @io.read_bytes(UInt8).to_i
Expand Down
2 changes: 1 addition & 1 deletion src/crystal/syntax_highlighter.cr
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ abstract class Crystal::SyntaxHighlighter
raise "Unterminated symbol array literal"
end
else
raise "Bug: shouldn't happen"
raise "BUG: Shouldn't happen"
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/crystal/system/event_loop.cr
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ end
{% elsif flag?(:win32) %}
require "./win32/event_loop_iocp"
{% else %}
{% raise "event_loop not supported" %}
{% raise "Event loop not supported" %}
{% end %}
2 changes: 1 addition & 1 deletion src/crystal/system/fiber.cr
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ end
{% elsif flag?(:win32) %}
require "./win32/fiber"
{% else %}
{% raise "fiber not supported" %}
{% raise "Fiber not supported" %}
{% end %}
2 changes: 1 addition & 1 deletion src/crystal/system/thread.cr
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ require "./thread_condition_variable"
{% elsif flag?(:win32) %}
require "./win32/thread"
{% else %}
{% raise "thread not supported" %}
{% raise "Thread not supported" %}
{% end %}
2 changes: 1 addition & 1 deletion src/crystal/system/thread_condition_variable.cr
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ end
{% elsif flag?(:win32) %}
require "./win32/thread_condition_variable"
{% else %}
{% raise "thread condition variable not supported" %}
{% raise "Thread condition variable not supported" %}
{% end %}
2 changes: 1 addition & 1 deletion src/crystal/system/thread_mutex.cr
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ end
{% elsif flag?(:win32) %}
require "./win32/thread_mutex"
{% else %}
{% raise "thread mutex not supported" %}
{% raise "Thread mutex not supported" %}
{% end %}
2 changes: 1 addition & 1 deletion src/crystal/system/unix/process.cr
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ struct Crystal::System::Process

if args
unless command.includes?(%("${@}"))
raise ArgumentError.new(%(can't specify arguments in both command and args without including "${@}" into your command))
raise ArgumentError.new(%(Can't specify arguments in both command and args without including "${@}" into your command))
end

{% if flag?(:freebsd) || flag?(:dragonfly) %}
Expand Down
2 changes: 1 addition & 1 deletion src/crystal/system/win32/process.cr
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct Crystal::System::Process
raise RuntimeError.from_winerror("GetExitCodeProcess")
end
if exit_code == LibC::STILL_ACTIVE
raise "BUG: process still active"
raise "BUG: Process still active"
end
exit_code
end
Expand Down
2 changes: 1 addition & 1 deletion src/crystal/system/win32/socket.cr
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ module Crystal::System::Socket
end

unless schedule_overlapped(read_timeout)
raise IO::TimeoutError.new("accept timed out")
raise IO::TimeoutError.new("#{method} timed out")
end

operation.wsa_result(socket) do |error|
Expand Down
4 changes: 2 additions & 2 deletions src/dir/glob.cr
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,10 @@ class Dir
next_pos = pos - 1
case cmd
in RootDirectory
raise "unreachable" if path
raise "Unreachable" if path
path_stack << {next_pos, root, nil}
in DirectoriesOnly
raise "unreachable" unless path
raise "Unreachable" unless path
# FIXME: [win32] File::SEPARATOR_STRING comparison is not sufficient for Windows paths.
if path == File::SEPARATOR_STRING
fullpath = path
Expand Down
2 changes: 1 addition & 1 deletion src/docs_pseudo_methods.cr
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class Object
# typeof(a.as(Bool)) # Compile Error: can't cast (Int32 | String) to Bool
#
# typeof(a.as(String)) # => String
# a.as(String) # Runtime Error: cast from Int32 to String failed
# a.as(String) # Runtime Error: Cast from Int32 to String failed
#
# typeof(a.as(Int32 | Bool)) # => Int32
# a.as(Int32 | Bool) # => 1
Expand Down
2 changes: 1 addition & 1 deletion src/exception/call_stack/stackwalk.cr
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ struct Exception::CallStack
# TODO: use WOW64_CONTEXT in place of CONTEXT
{% raise "x86 not supported" %}
{% else %}
{% raise "architecture not supported" %}
{% raise "Architecture not supported" %}
{% end %}

stack_frame = LibC::STACKFRAME64.new
Expand Down
2 changes: 1 addition & 1 deletion src/float/printer/dragonbox.cr
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ module Float::Printer::Dragonbox
{% elsif D::KAPPA == 2 %}
Div.check_divisibility_and_divide_by_pow10_k2(n)
{% else %}
{% raise "expected kappa == 1 or kappa == 2" %}
{% raise "Expected kappa == 1 or kappa == 2" %}
{% end %}
end
end
Expand Down
Loading

0 comments on commit b65280a

Please sign in to comment.