Skip to content

Commit

Permalink
build: migrate to Typescript target of ES2022 and use Error.cause
Browse files Browse the repository at this point in the history
Project-wide upgrade to Typescript target of ES2022 so that we can use
the new Error APIs.

Wherever possible we should now use the new `cause`
property of the built-in `Error` type in combination
with the `asError(unknown)` utility function:
```typescript
import { asError } from "@hyperledger/cactus-common";

try {
    await performSomeImportantOperation();
} catch (ex: unknown) {
    const cause = asError(ex);
    throw new Error("Something went wrong while doing something.", { cause });
}
```
More information about the EcmaScript proposal that made this possible:
https://github.com/tc39/proposal-error-cause

Fixes #3592

Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
  • Loading branch information
petermetz committed Oct 17, 2024
1 parent a4ec611 commit c5dc99e
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"importHelpers": true,
"target": "ES2022",
"lib": [
"es2018",
"ES2022",
"dom"
],
"resolveJsonModule": true,
Expand Down
6 changes: 2 additions & 4 deletions examples/test-run-transaction/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
"compilerOptions": {
/* Basic Options */
"incremental": true, /* Enable incremental compilation */
"target": "ES2017", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"target": "ES2022", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"module": "CommonJS", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"lib": [
"es2015",
"es2016",
"es2017",
"ES2022",
"dom"
], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@ import { RuntimeError } from "run-time-error-cjs";
import { coerceUnknownToError } from "./coerce-unknown-to-error";

/**
* ## DEPRECATED
*
* Instead of relying on this function, in the future, use the new `cause`
* property of the built-in `Error` type in combination
* with the `asError(unknown)` utility function:
* ```typescript
* import { asError } from "@hyperledger/cactus-common";
*
* try {
* await performSomeImportantOperation();
* } catch (ex: unknown) {
* const cause = asError(ex);
* throw new Error("Something went wrong while doing something.", { cause });
* }
* ```
* More information about the EcmaScript proposal that made this possible:
* https://github.com/tc39/proposal-error-cause
*
* ## The Old Documentation Prior to the Deprecation:
* ### STANDARD EXCEPTION HANDLING - EXAMPLE WITH RE-THROW:
*
* Use the this utility function and pass in any throwable of whatever type and format
Expand Down Expand Up @@ -77,6 +96,7 @@ import { coerceUnknownToError } from "./coerce-unknown-to-error";
* return result; // 42
* }
* ```
* @deprecated
*
* @param message The contextual information that will be passed into the
* constructor of the returned {@link RuntimeError} instance.
Expand All @@ -93,9 +113,28 @@ export function createRuntimeErrorWithCause(
}

/**
* ## DEPRECATED
*
* Instead of relying on this function, in the future, use the new `cause`
* property of the built-in `Error` type in combination
* with the `asError(unknown)` utility function:
* ```typescript
* import { asError } from "@hyperledger/cactus-common";
*
* try {
* await performSomeImportantOperation();
* } catch (ex: unknown) {
* const cause = asError(ex);
* throw new Error("Something went wrong while doing something.", { cause });
* }
* ```
* More information about the EcmaScript proposal that made this possible:
* https://github.com/tc39/proposal-error-cause
*
* An alias to the `createRuntimeErrorWithCause` function for those prefering
* a shorter utility for their personal style.
*
* @deprecated
* @see {@link createRuntimeErrorWithCause}
* @returns `RuntimeError`
*/
Expand Down
7 changes: 2 additions & 5 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@
},
/* Basic Options */
"incremental": true, /* Enable incremental compilation */
"target": "ES2017", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"target": "ES2022", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"module": "CommonJS", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"lib": [
"es2015",
"es2016",
"es2017",
"es2019",
"ES2022",
"dom"
], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
Expand Down
7 changes: 2 additions & 5 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,10 @@
],
"compilerOptions": {
"incremental": true,
"target": "ES2017",
"target": "ES2022",
"module": "Node16",
"lib": [
"es2015",
"es2016",
"es2017",
"es2019",
"ES2022",
"dom"
] /* Specify library files to be included in the compilation. */,
// "allowJs": true, /* Allow javascript files to be compiled. */
Expand Down

0 comments on commit c5dc99e

Please sign in to comment.