R.Debug Class
Debugging utilities embedded with R.
Provides conditionals for dev/prod mode and associated assertions to avoid lengthy try/catch blocks in prod mode.
Item Index
Methods
_mode
()
String
private
Returns:
string The basic string
breakpoint
()
public
Trigger a debugger breakpoint without raising jshint errors.
check
()
Boolean
public
Runs assert from node core with the same arguments.
Throws if the assert fails and the current mode is dev.
console.error if the assert fails and the current mode is prod.
No side effect if the assert doesn't fail.
Returns:
Truthy only if the assert doesn't fail. False if the assert fails and not in dev mode.
dev
-
fn
Runs a function iff the current mode is dev.
Parameters:
-
fn
FunctionThe function to invoke iff the current mode is dev.
Returns:
- The return value of fn iff the current mode is dev, undefined otherwise.
extendError
-
originalErr
-
wrappingErr
Extends an Error to provide additional information while preserving the error stack.
Uses VError under the hood.
Parameters:
-
originalErr
ErrorThe original error.
-
wrappingErr
Error | StringThe error to use as wrapper.
Returns:
The new, extended Error.
isDev
()
Boolean
public
Returns a boolean describing whether the current mode is dev.
Returns:
boolean Truthy iff the current mode is dev.
isProd
()
Boolean
public
Returns a boolean describing whether the current mode is prod.
Returns:
boolean Truthy iff the current mode is prod.
maybeDev
-
fn
Returns a function iff the current mode is dev, otherwise returns a noop function.
"dev-only" maybe monad.
Parameters:
-
fn
FunctionThe function to be returned if the current mode is dev.
Returns:
The original function iff the current mode is dev, no-op function otherwise.
maybeProd
-
fn
Returns a function iff the current mode is prod, otherwise returns a noop function.
"prod-only" maybe monad.
Parameters:
-
fn
FunctionThe function to be returned if the current mode is prod.
Returns:
The original function iff the current mode is prod, no-op function otherwise.
prod
-
fn
Runs a function iff the current mode is prod.
Parameters:
-
fn
FunctionThe function to invoke iff the current mode is prod.
Returns:
- The return value of fn iff the current mode is prod, undefined otherwise.
rethrow
-
[wrappingErr]
Returns a function that will rethrow when passed an error.
Parameters:
-
[wrappingErr]
Error | String optionalOptionnal error to use as wrapper.
setMode
-
mode
Manually override mode to either 'production' or 'development'.
Use this if you don't want to use envify.
Parameters:
-
mode
String