-- table.concat but allows booleans

local function tableConcat(t, sep)
	for i, v in t do
		if type(v) == "boolean" then
			t[i] = tostring(v)
		end
	end
	
	table.concat(t, sep)
	
	return t
end

local function dumpFormatter(dump, start, ending)
	-- "\n\n -- " .. start .. " --\n\n" .. dump .. "\n -- " .. ending .. " --"	
	return `\n\n -- {start} --\n\n{dump}\n -- {ending} --\n`
end

local class = {}

function ErrorFormat(title: string, nonFatal: boolean?, traceback: string?)
	return function(errorMessage: string)
		errorMessage = `{title} {errorMessage}{dumpFormatter(traceback or debug.traceback(nil, 2), "Stack Trace", "Stack End")}`
		
		if nonFatal then
			task.spawn(error, errorMessage, 0)
		else
			error(errorMessage, 0)
		end
	end
end

return ErrorFormat
