@openmrs/esm-error-handling 5.3.3-pre.1240 → 5.3.3-pre.1247
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +10 -10
- package/dist/openmrs-esm-error-handling.js.map +1 -1
- package/jest.config.js +4 -4
- package/package.json +2 -2
- package/src/index.ts +11 -14
- package/src/openmrs-esm-error-handling.test.js +7 -7
- package/webpack.config.js +15 -15
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
[
|
|
2
|
-
[
|
|
3
|
-
[
|
|
4
|
-
[
|
|
5
|
-
[
|
|
6
|
-
[
|
|
7
|
-
[
|
|
8
|
-
[
|
|
9
|
-
[
|
|
10
|
-
[
|
|
1
|
+
[34m@openmrs/esm-error-handling:build[0m: cache hit, replaying output [2mea9a157b0d4d21c4[0m
|
|
2
|
+
[34m@openmrs/esm-error-handling:build: [0mBrowserslist: caniuse-lite is outdated. Please run:
|
|
3
|
+
[34m@openmrs/esm-error-handling:build: [0m npx update-browserslist-db@latest
|
|
4
|
+
[34m@openmrs/esm-error-handling:build: [0m Why you should do it regularly: https://github.com/browserslist/update-db#readme
|
|
5
|
+
[34m@openmrs/esm-error-handling:build: [0masset [1m[32mopenmrs-esm-error-handling.js[39m[22m 1.87 KiB [1m[32m[emitted][39m[22m [1m[32m[minimized][39m[22m (name: main) 1 related asset
|
|
6
|
+
[34m@openmrs/esm-error-handling:build: [0mruntime modules 670 bytes 3 modules
|
|
7
|
+
[34m@openmrs/esm-error-handling:build: [0mbuilt modules 2.08 KiB [1m[33m[built][39m[22m
|
|
8
|
+
[34m@openmrs/esm-error-handling:build: [0m [1m./src/index.ts[39m[22m 2.04 KiB [1m[33m[built][39m[22m [1m[33m[code generated][39m[22m
|
|
9
|
+
[34m@openmrs/esm-error-handling:build: [0m [1mexternal "@openmrs/esm-globals"[39m[22m 42 bytes [1m[33m[built][39m[22m [1m[33m[code generated][39m[22m
|
|
10
|
+
[34m@openmrs/esm-error-handling:build: [0mwebpack 5.88.0 compiled [1m[32msuccessfully[39m[22m in 5536 ms
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openmrs-esm-error-handling.js","mappings":"8MAAAA,EAAOC,QAAUC,C,GCCbC,EAA2B,CAAC,EAGhC,SAASC,EAAoBC,GAE5B,IAAIC,EAAeH,EAAyBE,GAC5C,QAAqBE,IAAjBD,EACH,OAAOA,EAAaL,QAGrB,IAAID,EAASG,EAAyBE,GAAY,CAGjDJ,QAAS,CAAC,GAOX,OAHAO,EAAoBH,GAAUL,EAAQA,EAAOC,QAASG,GAG/CJ,EAAOC,OACf,CCrBAG,EAAoBK,EAAI,CAACR,EAASS,KACjC,IAAI,IAAIC,KAAOD,EACXN,EAAoBQ,EAAEF,EAAYC,KAASP,EAAoBQ,EAAEX,EAASU,IAC5EE,OAAOC,eAAeb,EAASU,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,IAE1E,ECNDP,EAAoBQ,EAAI,CAACK,EAAKC,IAAUL,OAAOM,UAAUC,eAAeC,KAAKJ,EAAKC,GCClFd,EAAoBkB,EAAKrB,IACH,oBAAXsB,QAA0BA,OAAOC,aAC1CX,OAAOC,eAAeb,EAASsB,OAAOC,YAAa,CAAEC,MAAO,WAE7DZ,OAAOC,eAAeb,EAAS,aAAc,CAAEwB,OAAO,GAAO,E,
|
|
1
|
+
{"version":3,"file":"openmrs-esm-error-handling.js","mappings":"8MAAAA,EAAOC,QAAUC,C,GCCbC,EAA2B,CAAC,EAGhC,SAASC,EAAoBC,GAE5B,IAAIC,EAAeH,EAAyBE,GAC5C,QAAqBE,IAAjBD,EACH,OAAOA,EAAaL,QAGrB,IAAID,EAASG,EAAyBE,GAAY,CAGjDJ,QAAS,CAAC,GAOX,OAHAO,EAAoBH,GAAUL,EAAQA,EAAOC,QAASG,GAG/CJ,EAAOC,OACf,CCrBAG,EAAoBK,EAAI,CAACR,EAASS,KACj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M,wBAAyBuB,EAAMC,SAC7CN,EAAAA,EAAAA,2BAA0B,CACxBC,YAAyB,QAAZI,EAAAA,EAAMC,cAAND,IAAAA,EAAAA,EAAgB,iDAC7BH,KAAM,QACNC,MAAO,SAEX,C","sources":["webpack://@openmrs/esm-error-handling/external system \"@openmrs/esm-globals\"","webpack://@openmrs/esm-error-handling/webpack/bootstrap","webpack://@openmrs/esm-error-handling/webpack/runtime/define property getters","webpack://@openmrs/esm-error-handling/webpack/runtime/hasOwnProperty shorthand","webpack://@openmrs/esm-error-handling/webpack/runtime/make namespace object","webpack://@openmrs/esm-error-handling/./src/index.ts"],"sourcesContent":["module.exports = __WEBPACK_EXTERNAL_MODULE__728__;","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","/** @module @category Error Handling */\nimport { dispatchNotificationShown } from '@openmrs/esm-globals';\n\nwindow.onerror = function (error) {\n console.error('Unexpected error: ', error);\n dispatchNotificationShown({\n description: error ?? 'Oops! An unexpected error occurred.',\n kind: 'error',\n title: 'Error',\n });\n return false;\n};\n\nwindow.onunhandledrejection = function (event) {\n console.error('Unhandled rejection: ', event.reason);\n dispatchNotificationShown({\n description: event.reason ?? 'Oops! An unhandled promise rejection occurred.',\n kind: 'error',\n title: 'Error',\n });\n};\n\nexport function reportError(err) {\n const error = ensureErrorObject(err);\n setTimeout(() => {\n throw error;\n });\n}\n\nexport function createErrorHandler() {\n const outgoingErr = Error();\n return (incomingErr) => {\n const finalErr = ensureErrorObject(incomingErr);\n finalErr.stack += `\\nAsync stacktrace:\\n${outgoingErr.stack}`;\n reportError(incomingErr);\n };\n}\n\nfunction ensureErrorObject(thing: any) {\n let message;\n\n if (thing instanceof Error) {\n return thing;\n } else if (thing === null) {\n return Error(`'null' was thrown as an error`);\n } else if (typeof thing === 'object') {\n try {\n message = `Object thrown as error: ${JSON.stringify(thing)}`;\n } catch (e) {\n message = `Object thrown as error with the following properties: ${Object.keys(thing)}`;\n }\n return Error(message);\n } else if (thing === undefined) {\n return Error(`'undefined' was thrown as an error`);\n } else {\n return Error(thing.toString());\n }\n}\n"],"names":["module","exports","__WEBPACK_EXTERNAL_MODULE__728__","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","undefined","__webpack_modules__","d","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","r","Symbol","toStringTag","value","reportError","err","error","ensureErrorObject","setTimeout","createErrorHandler","outgoingErr","Error","incomingErr","stack","thing","message","JSON","stringify","e","keys","toString","window","onerror","console","dispatchNotificationShown","description","kind","title","onunhandledrejection","event","reason"],"sourceRoot":""}
|
package/jest.config.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
module.exports = {
|
|
2
2
|
transform: {
|
|
3
|
-
|
|
3
|
+
'^.+\\.tsx?$': ['@swc/jest'],
|
|
4
4
|
},
|
|
5
5
|
setupFiles: [],
|
|
6
6
|
moduleNameMapper: {
|
|
7
|
-
|
|
7
|
+
'@openmrs/esm-globals': '<rootDir>/__mocks__/openmrs-esm-globals.mock.tsx',
|
|
8
8
|
},
|
|
9
|
-
testEnvironment:
|
|
9
|
+
testEnvironment: 'jsdom',
|
|
10
10
|
testEnvironmentOptions: {
|
|
11
|
-
url:
|
|
11
|
+
url: 'http://localhost/',
|
|
12
12
|
},
|
|
13
13
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openmrs/esm-error-handling",
|
|
3
|
-
"version": "5.3.3-pre.
|
|
3
|
+
"version": "5.3.3-pre.1247",
|
|
4
4
|
"license": "MPL-2.0",
|
|
5
5
|
"description": "An ES module to help with error handling",
|
|
6
6
|
"browser": "dist/openmrs-esm-error-handling.js",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"@openmrs/esm-globals": "5.x"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@openmrs/esm-globals": "5.3.3-pre.
|
|
43
|
+
"@openmrs/esm-globals": "5.3.3-pre.1247"
|
|
44
44
|
},
|
|
45
45
|
"stableVersion": "5.3.2"
|
|
46
46
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,23 +1,22 @@
|
|
|
1
1
|
/** @module @category Error Handling */
|
|
2
|
-
import { dispatchNotificationShown } from
|
|
2
|
+
import { dispatchNotificationShown } from '@openmrs/esm-globals';
|
|
3
3
|
|
|
4
4
|
window.onerror = function (error) {
|
|
5
|
-
console.error(
|
|
5
|
+
console.error('Unexpected error: ', error);
|
|
6
6
|
dispatchNotificationShown({
|
|
7
|
-
description: error ??
|
|
8
|
-
kind:
|
|
9
|
-
title:
|
|
7
|
+
description: error ?? 'Oops! An unexpected error occurred.',
|
|
8
|
+
kind: 'error',
|
|
9
|
+
title: 'Error',
|
|
10
10
|
});
|
|
11
11
|
return false;
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
window.onunhandledrejection = function (event) {
|
|
15
|
-
console.error(
|
|
15
|
+
console.error('Unhandled rejection: ', event.reason);
|
|
16
16
|
dispatchNotificationShown({
|
|
17
|
-
description:
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
title: "Error",
|
|
17
|
+
description: event.reason ?? 'Oops! An unhandled promise rejection occurred.',
|
|
18
|
+
kind: 'error',
|
|
19
|
+
title: 'Error',
|
|
21
20
|
});
|
|
22
21
|
};
|
|
23
22
|
|
|
@@ -44,13 +43,11 @@ function ensureErrorObject(thing: any) {
|
|
|
44
43
|
return thing;
|
|
45
44
|
} else if (thing === null) {
|
|
46
45
|
return Error(`'null' was thrown as an error`);
|
|
47
|
-
} else if (typeof thing ===
|
|
46
|
+
} else if (typeof thing === 'object') {
|
|
48
47
|
try {
|
|
49
48
|
message = `Object thrown as error: ${JSON.stringify(thing)}`;
|
|
50
49
|
} catch (e) {
|
|
51
|
-
message = `Object thrown as error with the following properties: ${Object.keys(
|
|
52
|
-
thing
|
|
53
|
-
)}`;
|
|
50
|
+
message = `Object thrown as error with the following properties: ${Object.keys(thing)}`;
|
|
54
51
|
}
|
|
55
52
|
return Error(message);
|
|
56
53
|
} else if (thing === undefined) {
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
jest.mock(
|
|
2
|
-
const { reportError } = jest.requireActual(
|
|
1
|
+
jest.mock('./index');
|
|
2
|
+
const { reportError } = jest.requireActual('./index');
|
|
3
3
|
|
|
4
4
|
jest.useFakeTimers();
|
|
5
|
-
describe(
|
|
6
|
-
it(
|
|
5
|
+
describe('error handler', () => {
|
|
6
|
+
it('transfrom the input in valid error object if it is not already an error obejct', () => {
|
|
7
7
|
expect(() => {
|
|
8
|
-
reportError(
|
|
8
|
+
reportError('error');
|
|
9
9
|
jest.runAllTimers();
|
|
10
|
-
}).toThrow(
|
|
10
|
+
}).toThrow('error');
|
|
11
11
|
|
|
12
12
|
expect(() => {
|
|
13
|
-
reportError({ error:
|
|
13
|
+
reportError({ error: 'error' });
|
|
14
14
|
jest.runAllTimers();
|
|
15
15
|
}).toThrow('Object thrown as error: {"error":"error"}');
|
|
16
16
|
|
package/webpack.config.js
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
const ForkTsCheckerWebpackPlugin = require(
|
|
2
|
-
const { resolve } = require(
|
|
3
|
-
const { CleanWebpackPlugin } = require(
|
|
4
|
-
const { BundleAnalyzerPlugin } = require(
|
|
1
|
+
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
|
|
2
|
+
const { resolve } = require('path');
|
|
3
|
+
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
|
|
4
|
+
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
|
|
5
5
|
|
|
6
|
-
const { peerDependencies } = require(
|
|
6
|
+
const { peerDependencies } = require('./package.json');
|
|
7
7
|
|
|
8
8
|
module.exports = (env) => ({
|
|
9
|
-
entry: [resolve(__dirname,
|
|
9
|
+
entry: [resolve(__dirname, 'src/index.ts')],
|
|
10
10
|
output: {
|
|
11
|
-
filename:
|
|
12
|
-
path: resolve(__dirname,
|
|
13
|
-
library: { type:
|
|
11
|
+
filename: 'openmrs-esm-error-handling.js',
|
|
12
|
+
path: resolve(__dirname, 'dist'),
|
|
13
|
+
library: { type: 'system' },
|
|
14
14
|
},
|
|
15
|
-
mode:
|
|
15
|
+
mode: 'production',
|
|
16
16
|
module: {
|
|
17
17
|
rules: [
|
|
18
18
|
{
|
|
19
19
|
test: /\.m?(js|ts|tsx)$/,
|
|
20
20
|
exclude: /node_modules/,
|
|
21
|
-
use:
|
|
21
|
+
use: 'swc-loader',
|
|
22
22
|
},
|
|
23
23
|
],
|
|
24
24
|
},
|
|
25
|
-
devtool:
|
|
25
|
+
devtool: 'source-map',
|
|
26
26
|
devServer: {
|
|
27
27
|
headers: {
|
|
28
|
-
|
|
28
|
+
'Access-Control-Allow-Origin': '*',
|
|
29
29
|
},
|
|
30
30
|
disableHostCheck: true,
|
|
31
31
|
},
|
|
@@ -34,10 +34,10 @@ module.exports = (env) => ({
|
|
|
34
34
|
new ForkTsCheckerWebpackPlugin(),
|
|
35
35
|
new CleanWebpackPlugin(),
|
|
36
36
|
new BundleAnalyzerPlugin({
|
|
37
|
-
analyzerMode: env && env.analyze ?
|
|
37
|
+
analyzerMode: env && env.analyze ? 'static' : 'disabled',
|
|
38
38
|
}),
|
|
39
39
|
],
|
|
40
40
|
resolve: {
|
|
41
|
-
extensions: [
|
|
41
|
+
extensions: ['.tsx', '.ts', '.jsx', '.js'],
|
|
42
42
|
},
|
|
43
43
|
});
|