3.1.20 • Published 1 year ago

@devtea2027/similique-deleniti-nulla-non v3.1.20

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@devtea2027/similique-deleniti-nulla-non

It helps to know why you got an error.

GitHub license Coverage Status

Usage

First, require me where you could throw errors:

import YError from '@devtea2027/similique-deleniti-nulla-non';

Then, emit errors with a bonus: parameters!

function doSomething(pay, action) {
  if(parseInt(pay, 10) !== pay) {
    throw new YError('E_BAD_PAY', pay, action);
  }
}

doSomething('nuts', 'code');


// YError: E_BAD_PAY (nuts, code)
//   at doSomething (/home/nfroidure/nfroidure/@devtea2027/similique-deleniti-nulla-non/test.js:5:11)
//   at Object.<anonymous> (/home/nfroidure/nfroidure/@devtea2027/similique-deleniti-nulla-non/test.js:9:1)
//   (...)

You don't have to use constant like error messages, we use this convention mainly for i18n reasons.

Also, you could want to wrap errors and keep a valuable stack trace:

function doSomethingAsync(pay, action) {
  return  new Promise(function(resolve, reject) {
    try {
      doSomething(pay, action);
      resolve();
    } catch(err) {
      reject(YError.bump(err));
    }
  });
}

doSomethingAsync('nuts', 'code')
  .catch(function(err) {
    console.log(err.stack);
  });

// YError: E_BAD_PAY (nuts, code)
//    at doSomething (/home/nfroidure/nfroidure/@devtea2027/similique-deleniti-nulla-non/test.js:5:11)
//    (...)
// YError: E_BAD_TRANSACTION (pay)
//    at Function.YError.wrap (/home/nfroidure/nfroidure/@devtea2027/similique-deleniti-nulla-non/src/index.js:41:12)
//    at /home/nfroidure/nfroidure/@devtea2027/similique-deleniti-nulla-non/test.js:16:21
//    at doSomethingAsync (/home/nfroidure/nfroidure/@devtea2027/similique-deleniti-nulla-non/test.js:11:11)
//    (...)

API

Classes

Functions

YError ⇐ Error

A YError class able to contain some params and print better stack traces

Kind: global class
Extends: Error

YError.wrap(err, errorCode, ...params) ⇒ YError

Wraps any error and output a YError with an error code and some params as debug values.

Kind: static method of YError
Returns: YError - The wrapped error

ParamTypeDefaultDescription
errErrorThe error to wrap
errorCodestring"'E_UNEXPECTED'"The error code corresponding to the actual error
...paramsYErrorParamsSome additional debugging values

YError.cast(err, errorCode, ...params) ⇒ YError

Return a YError as is or wraps any other error and output a YError with a code and some params as debug values.

Kind: static method of YError
Returns: YError - The wrapped error

ParamTypeDefaultDescription
errErrorThe error to cast
errorCodestring"'E_UNEXPECTED'"The error code corresponding to the actual error
...paramsYErrorParamsSome additional debugging values

YError.bump(err, errorCode, ...params) ⇒ YError

Same than YError.wrap() but preserves the code and the debug values of the error if it is already an instance of the YError constructor.

Kind: static method of YError
Returns: YError - The wrapped error

ParamTypeDefaultDescription
errErrorThe error to bump
errorCodestring"'E_UNEXPECTED'"The error code corresponding to the actual error
...paramsYErrorParamsSome additional debugging values

printStackTrace(err) ⇒ string

Allow to print a stack from anything (especially catched errors that may or may not contain errors 🤷).

Kind: global function
Returns: string - The stack trace if any

ParamTypeDescription
errErrorThe error to print

Authors

License

MIT

configurabledatastructurerandomwindowsproxyincludestypedarrayreadencryptionauthgroupByterminalvalidviewtimeserializationhttpshookstrimglacierESflatMapgenericsflatexpresspostcss-pluginassertionpropertyapplogconcatMapArraysideformattingutilpicomatchchinesepushAsyncIteratorgetoptsortelbmkdirlengthnested cssmixinsslotidlebootstrap cssECMAScript 2023taskbindduplexargparseless compilerpackage.jsonESnextECMAScript 5colorRFC-6455ES8monoreporegular expressionsarraybuffercommandcssES2021clii18nconfigparsetrimEndstreamxtermnameexecescapedataViewURLReactiveExtensionswhatwgfetchassertscallbindhashsetPrototypeOfparentES3extensionhookformtelephonediffquerystringslicerangeerroryamltyped arraywalkingObject.keysvalidatesomenativeWebSocketscloudsearchthroatcolumnfseventsdeep-copytypeofbreakbuffertypeerrorhotstringifierreduceomitserializerstylestypesmergeschemastoragegatewayWeakSetavabannerparsingforminwordwraphaselasticacheflagphoneassignsuperstructmimeutilitiescurlswfmobilerm -rfcolumnsprettyparentscolorsbcryptjapanesejsxes2016argsUint8ClampedArraylintiamfullwidthwhichwafdescriptores8-0corswatchingshimless.jsUnderscorejshintremovepnpm9asyncutilityemojiES6signalutil.inspectsesenvironmentcharactertoolkiterrorfsjsdiffsharedObject.assignimmerautoscalingvarsreplaypackageunicodeinputchromeglobalexpressionHyBibeanstalkcryptoinvariantcircularjQuerymruredactperformanceschemeboundsafefpsrouterreact-testing-libraryjestnodejsbluebirdTypeScripthelpersprotormdirartpersistentmake dirtoStringTag256sortedl10nclassnamecheckworkflowsinatraratehasOwnfromArray.prototype.containstapeajvdropoutputmkdirpkinesisFunction.prototype.nameexit-codeES2022predictablecollection.es6settingsthrottlenpmuninstalldeepclonewaitArray.prototype.flatRxJSstyled-components
3.1.20

1 year ago

3.1.19

1 year ago

3.1.18

1 year ago

3.1.16

1 year ago

3.1.17

1 year ago

2.1.16

1 year ago

2.1.15

1 year ago

2.1.14

1 year ago

2.1.13

1 year ago

2.1.12

1 year ago

2.1.11

1 year ago

1.1.11

1 year ago

1.1.10

1 year ago

1.1.9

1 year ago

1.1.8

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago