Skip to content

Commit

Permalink
Refactor LocationlessException to Crystal::Error
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota committed Jan 5, 2021
1 parent 015c568 commit 06e5498
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/compiler/crystal/codegen/codegen.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2027,7 +2027,7 @@ module Crystal
if raise_overflow_fun = @raise_overflow_fun
check_main_fun RAISE_OVERFLOW_NAME, raise_overflow_fun
else
raise LocationlessException.new("Missing __crystal_raise_overflow function, either use std-lib's prelude or define it")
raise Error.new("Missing __crystal_raise_overflow function, either use std-lib's prelude or define it")
end
end

Expand Down
4 changes: 2 additions & 2 deletions src/compiler/crystal/codegen/target.cr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require "llvm"
require "../exception"
require "../error"

class Crystal::Codegen::Target
class Error < Crystal::LocationlessException
class Error < Crystal::Error
end

getter architecture : String
Expand Down
10 changes: 5 additions & 5 deletions src/compiler/crystal/command.cr
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,6 @@ class Crystal::Command
error "unknown command: #{command}"
end
end
rescue ex : Crystal::LocationlessException
report_warnings

error ex.message
rescue ex : Crystal::Exception
report_warnings

Expand All @@ -137,6 +133,10 @@ class Crystal::Command
STDERR.puts ex
end
exit 1
rescue ex : Crystal::Error
report_warnings

error ex.message
rescue ex : OptionParser::Exception
error ex.message
rescue ex
Expand Down Expand Up @@ -623,7 +623,7 @@ class Crystal::Command
private def use_crystal_opts
@options = Process.parse_arguments(ENV.fetch("CRYSTAL_OPTS", "")).concat(options)
rescue ex
raise LocationlessException.new("Failed to parse CRYSTAL_OPTS: #{ex.message}")
raise Error.new("Failed to parse CRYSTAL_OPTS: #{ex.message}")
end

private def new_compiler
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/crystal/crystal_path.cr
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require "./config"
require "./exception"
require "./error"

module Crystal
struct CrystalPath
class NotFoundError < LocationlessException
class NotFoundError < Crystal::Error
getter filename
getter relative_to

Expand Down
5 changes: 5 additions & 0 deletions src/compiler/crystal/error.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Crystal
# Base class for all errors in the compiler.
class Error < ::Exception
end
end
27 changes: 2 additions & 25 deletions src/compiler/crystal/exception.cr
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
require "./util"
require "./error"
require "colorize"

module Crystal
abstract class Exception < ::Exception
abstract class Exception < Error
property? color = false
property? error_trace = false

Expand Down Expand Up @@ -76,30 +77,6 @@ module Crystal
end
end

class LocationlessException < Exception
def to_s_with_source(io : IO, source)
io << @message
end

def append_to_s(io : IO, source)
io << @message
end

def has_location?
false
end

def deepest_error_message
@message
end

def to_json_single(json)
json.object do
json.field "message", @message
end
end
end

module ErrorFormat
MACRO_LINES_TO_SHOW = 3
OFFSET_FROM_LINE_NUMBER_DECORATOR = 6
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/tools/playground/server.cr
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ module Crystal::Playground
end
end

class Error < Crystal::LocationlessException
class Error < Crystal::Error
end

class Server
Expand Down

0 comments on commit 06e5498

Please sign in to comment.