Module Error

Produces auto-formatting auto-serializing errors handlers.

Module Status: Experimental 2020-10-31.

Usage:

  • local Error = require('__eradicators-library__/erlib/factorio/Error')()
    
  • Error.Error('MyModName','MyErrorName',"Sorry, i can't do that Dave!",nil,nil,
    nil,'shit',{'is','hitting',{'the','fence!'}},{'near','the','fox'}, nil,nil,nil )
    
  • > ##### [MyModName : MyErrorName] #####
    > I suspected this might happen. Please tell me how you got here.
    >
    > Sorry, i can't do that Dave!
    > shit
    > {"is", "hitting", {"the", "fence!"}}
    > {"near", "the", "fox"}
    >
    > (6 nil values removed.)
    > control.lua:18 > some_module.lua:67
    > ############################
    

Functions

Error([prefix[, postfix[, ...]]]) The raw error handler called by all Error instances.
Stopper([prefix="YourModName"], postfix) Fabricates a customized ErrorRaiser with closurized prefix and postfix.
Asserter(error_raiser) Assert, but with a custom error function.

ErrorRaiser

ErrorRaiser([...]) Raises an error with the given message and the closurized pre- and postfix.


Functions

Error([prefix[, postfix[, ...]]])
The raw error handler called by all Error instances. Will print an error message as shown above. All varargs will be serialized if required and printed one per line.

Parameters:

  • prefix AnyValue the prefix part of the error message header. This should usually be the erroring mods name. (optional)
  • postfix AnyValue the name of the module that caused the error. (optional)
  • ... AnyValue all the AnyValue you want in the message. (optional)
Stopper([prefix="YourModName"], postfix)
Fabricates a customized ErrorRaiser with closurized prefix and postfix.

Parameters:

Returns:

    ErrorRaiser

Raises:

CustomError

Usage:

  • local MyError = Error.Stopper('MyModName','MyErrorName')
    if not is_everything_ok then
      MyError('something is broken!')
      end
    
  • local MyError = Error.Stopper('MyErrorName')
    if not is_everything_ok then
      MyError('something is broken!')
      end
    
Asserter(error_raiser)
Assert, but with a custom error function.

Parameters:

Returns:

    function f(obj, ...) When called calls error_raiser(...) if obj was not truthy, else returns obj.

ErrorRaiser

ErrorRaiser([...])
Raises an error with the given message and the closurized pre- and postfix.

Parameters:

  • ... AnyValue Arbitrary values to be displayed in the error message. (optional)

Raises:

CustomError
generated by LDoc 1.4.6 Last updated 2021-09-10 19:51:19