Skip to content

Commit

Permalink
Rename Crystal::Exception to CodeError
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota committed Jan 5, 2021
1 parent 4af91d6 commit 37bd2d1
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/compiler/crystal/command.cr
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class Crystal::Command
error "unknown command: #{command}"
end
end
rescue ex : Crystal::Exception
rescue ex : Crystal::CodeError
report_warnings

ex.color = @color
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/crystal/compiler.cr
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ module Crystal
# Compiles the given *source*, with *output_filename* as the name
# of the generated executable.
#
# Raises `Crystal::Exception` if there's an error in the
# Raises `Crystal::CodeError` if there's an error in the
# source code.
#
# Raises `InvalidByteSequenceError` if the source code is not
Expand All @@ -183,7 +183,7 @@ module Crystal
# contain all types and methods. This can be useful to generate
# API docs, analyze type relationships, etc.
#
# Raises `Crystal::Exception` if there's an error in the
# Raises `Crystal::CodeError` if there's an error in the
# source code.
#
# Raises `InvalidByteSequenceError` if the source code is not
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/crystal/exception.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ require "./error"
require "colorize"

module Crystal
abstract class Exception < Error
# Base class for all errors related to specific user code.
abstract class CodeError < Error
property? color = false
property? error_trace = false

Expand Down
4 changes: 2 additions & 2 deletions src/compiler/crystal/macros/interpreter.cr
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ module Crystal
@last = receiver.interpret(node.name, args, named_args, node.block, self)
rescue ex : MacroRaiseException
raise ex
rescue ex : Crystal::Exception
rescue ex : Crystal::CodeError
node.raise ex.message, inner: ex
rescue ex
node.raise ex.message
Expand Down Expand Up @@ -492,7 +492,7 @@ module Crystal

def resolve?(node : Generic)
resolve(node)
rescue Crystal::Exception
rescue Crystal::CodeError
nil
end

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

begin
generic_type = instance_type.as(GenericType).instantiate(type_vars_types)
rescue ex : Crystal::Exception
rescue ex : Crystal::CodeError
raise ex.message, ex
end
end
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/crystal/semantic/call.cr
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ class Crystal::Call
begin
block_type = lookup_node_type(match.context, output).virtual_type
block_type = program.nil if block_type.void?
rescue ex : Crystal::Exception
rescue ex : Crystal::CodeError
cant_infer_block_return_type
end
else
Expand All @@ -923,7 +923,7 @@ class Crystal::Call
if output.is_a?(ASTNode) && !output.is_a?(Underscore) && block_type.no_return?
begin
block_type = lookup_node_type(match.context, output).virtual_type
rescue ex : Crystal::Exception
rescue ex : Crystal::CodeError
if block_type
raise "couldn't match #{block_type} to #{output}", ex
else
Expand Down Expand Up @@ -992,7 +992,7 @@ class Crystal::Call
def bubbling_exception
begin
yield
rescue ex : Crystal::Exception
rescue ex : Crystal::CodeError
if obj = @obj
if name == "initialize"
# Avoid putting 'initialize' in the error trace
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/semantic/conversions.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Crystal::Conversions

begin
convert_call.accept visitor
rescue ex : Crystal::Exception
rescue ex : Crystal::CodeError
if ex.message.try(&.includes?("undefined method '#{convert_call_name}'"))
return nil
end
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/crystal/semantic/exception.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ require "../exception"
require "../types"

module Crystal
class TypeException < Exception
class TypeException < CodeError
include ErrorFormat

getter node
property inner : Exception?
property inner : CodeError?
getter line_number : Int32?
getter column_number : Int32
getter size : Int32
Expand Down Expand Up @@ -171,7 +171,7 @@ module Crystal
end
end

class MethodTraceException < Exception
class MethodTraceException < CodeError
def initialize(@owner : Type?, @trace : Array(ASTNode), @nil_reason : NilReason?, @show : Bool)
super(nil)
end
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/crystal/semantic/main_visitor.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1294,7 +1294,7 @@ module Crystal

begin
call.recalculate
rescue ex : Crystal::Exception
rescue ex : Crystal::CodeError
node.raise "error instantiating #{node}", ex
end

Expand Down Expand Up @@ -1916,7 +1916,7 @@ module Crystal

begin
body.accept visitor
rescue ex : Crystal::Exception
rescue ex : Crystal::CodeError
node.raise ex.message, ex
end

Expand Down
4 changes: 2 additions & 2 deletions src/compiler/crystal/semantic/semantic_visitor.cr
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ abstract class Crystal::SemanticVisitor < Crystal::Visitor
end

node.raise "#{message}\n\n#{notes.join("\n")}"
rescue ex : Crystal::Exception
rescue ex : Crystal::CodeError
node.raise "while requiring \"#{node.string}\"", ex
rescue ex
raise Error.new("while requiring \"#{node.string}\"", ex)
Expand Down Expand Up @@ -439,7 +439,7 @@ abstract class Crystal::SemanticVisitor < Crystal::Visitor
yield
rescue ex : MacroRaiseException
node.raise ex.message, exception_type: MacroRaiseException
rescue ex : Crystal::Exception
rescue ex : Crystal::CodeError
node.raise "expanding macro", ex
end

Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/semantic/top_level_visitor.cr
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ class Crystal::TopLevelVisitor < Crystal::SemanticVisitor
target = current_type.metaclass.as(ModuleType)
begin
target.add_macro node
rescue ex : Crystal::Exception
rescue ex : Crystal::CodeError
node.raise ex.message
end

Expand Down
8 changes: 4 additions & 4 deletions src/compiler/crystal/semantic/type_lookup.cr
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class Crystal::Type

begin
return instance_type.instantiate_named_args(entries)
rescue ex : Crystal::Exception
rescue ex : Crystal::CodeError
node.raise "instantiating #{node}", inner: ex if @raise
end
when GenericType
Expand Down Expand Up @@ -257,7 +257,7 @@ class Crystal::Type
begin
num = interpreter.interpret(type.value)
type_vars << NumberLiteral.new(num)
rescue ex : Crystal::Exception
rescue ex : Crystal::CodeError
type_var.raise "expanding constant value for a number value", inner: ex
end
next
Expand Down Expand Up @@ -289,7 +289,7 @@ class Crystal::Type
else
instance_type.as(GenericType).instantiate(type_vars)
end
rescue ex : Crystal::Exception
rescue ex : Crystal::CodeError
node.raise "instantiating #{node}", inner: ex if @raise
end
end
Expand Down Expand Up @@ -375,7 +375,7 @@ class Crystal::Type
expressions = node.expressions.clone
begin
expressions.each &.accept visitor
rescue ex : Crystal::Exception
rescue ex : Crystal::CodeError
node.raise "typing typeof", inner: ex
end
program.type_merge expressions
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/syntax/exception.cr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "../exception"

module Crystal
class SyntaxException < Exception
class SyntaxException < CodeError
include ErrorFormat

getter line_number : Int32
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/crystal/tools/playground/server.cr
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ module Crystal::Playground
@tag = tag
begin
sources = self.class.instrument_and_prelude(@session_key, @port, tag, source)
rescue ex : Crystal::Exception
rescue ex : Crystal::CodeError
send_exception ex, tag
return
end
Expand Down Expand Up @@ -103,7 +103,7 @@ module Crystal::Playground

begin
value = Crystal.format source
rescue ex : Crystal::Exception
rescue ex : Crystal::CodeError
send_exception ex, tag
return
end
Expand Down Expand Up @@ -148,7 +148,7 @@ module Crystal::Playground
def append_exception(json, ex)
json.object do
json.field "message", ex.to_s
if ex.is_a?(Crystal::Exception)
if ex.is_a?(Crystal::CodeError)
json.field "payload" do
ex.to_json(json)
end
Expand Down

0 comments on commit 37bd2d1

Please sign in to comment.