local require = require
local setmetatable = setmetatable
local _ENV = require "strict" {}
local nmap = require "nmap"
local debugging = nmap.debugging
local verbosity = nmap.verbosity
local table = require "table"
local concat = table.concat
local insert = table.insert
local Oops = {
  new = function (self, message)
    local o = {message}
    setmetatable(o, self)
    self.__index = self
    return o
  end,
  push = function (self, message)
    insert(self, 1, message)
  end,
  __tostring = function (self)
    local banner = "The script encountered an error"
    local sep = ":\n- "
    if debugging() > 0 then
      return banner .. sep .. concat(self, sep)
    end
    if verbosity() > 0 then
      return banner .. ": " .. self[1]
    end
  end,
}
err = function (message, previous)
  local result
  if previous then
    if previous.push then
      result = previous
    else
      result = Oops:new(previous)
    end
    result:push(message)
  elseif message.push then
    result = message
  else
    result = Oops:new(message)
  end
  return result
end
local err = err
output = function (status, message)
  if status then
    return message
  else
    return err(message)
  end
end
local output = output
raise = function (message, status, previous, ...)
  local r = previous
  if not status then
    r = err(message, previous)
  end
  return status, r, ...
end
return _ENV
