class_name Error extends RefCounted

var message: String
var stack: Array

func _init(message: String):
    self.message = message
    stack = get_stack().slice(1)

func raise_self():
    Error.raise(message)

static func raise(message: String):
    push_error(message)
    assert(false)

func _to_string() -> String:
    var str = message
    for value in stack:
        str += "\r\n%s:%s - at function %s" % [value.source, value.line, value.function]
    return str

class NotImplemented extends Error:
    static var _message: String = "NotImplementedError: %s is not implemented"

    func _init(name: String):
        super(_message % name)

class InvalidArgument extends Error:
    static var _message: String = 'InvalidArgumentError: %s is not a valid argument'

    func _init(arg: Variant):
        super(_message % arg)
