Skip to content

Commit

Permalink
Merge pull request #345 from vmware/bugfix/issue-311-vroes-import-unk…
Browse files Browse the repository at this point in the history
…nown-error

[ecmascript] (#311)Fix for Unknown error on VROES.import

Added validation for module path (including for relative path with base path) and specified files for import in Module.import.
  • Loading branch information
bcpmihail committed Aug 19, 2024
2 parents 6de896e + 513d8c1 commit dd57325
Show file tree
Hide file tree
Showing 6 changed files with 593 additions and 128 deletions.
32 changes: 32 additions & 0 deletions docs/versions/latest/Release.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,38 @@ License plugin `<excludes>` uses hardcoded value defined in the `base-package` -

The default value of license plugin's `<excludes>` configuration can be overwritten by providing `<license.excludes>` property in a projects `pom.xml` -> `<properties>` tag.

### Change default return Object of `Array.from()` Method to be empty array

#### Previous Behavior

In case the object type of the array-like Object does not match any of the expected types (e.g. is a Number) the default case of `Array.from()` returns a clone of the object. This does not match the desired behaviour according to the official documentation.

```js
Array.from(10) // Output: 10
```

#### Current Behavior
In case the object type of the array-like Object does not match any of the expected types (e.g. is a Number) the default case of `Array.from()` returns an empty array.

```js
Array.from(10) // Output: []
```

### *VROES.import from invalid package throws Unknown error*

Fixed an issue with VROES.import() in ecmascript Module.

#### Previous Behavior

VROES import from an invalid module path resulted in Unknown error.
The Unknown error could not be caught in a try/catch block and was not shown in the logs.

#### New Behavior

VROES import from a missing/invalid module path, or import of non-existing elements of a valid module,
result in more detailed errors in the logs. No exceptions are thrown by default (as per the existing behaviour)
but there is an option to alter the error handling behaviour via an optional parameter in import.from().

## Upgrade procedure

[//]: # (Explain in details if something needs to be done)
51 changes: 42 additions & 9 deletions packages/ecmascript/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ECMAScript library
The purpose of the library is to provide runtime support for Typescript based projects by handling the export/import features of ECMA script as well as providing implementations for Set, Map and sum of the Array functions.

# Usage
## Usage
This library is not to be used directly.

## Export
Expand All @@ -13,28 +13,28 @@ export function myFunction() {}
export var myVar = 5;

ESModule.export()
.named("MyClass", MyClass)
.named("myFunction", myFunction)
.named("myVar", myVar)
.build();
.named("MyClass", MyClass)
.named("myFunction", myFunction)
.named("myVar", myVar)
.build();
```

Default exports (function)
```js
export default function myFunction() {}

ESModule.export()
.default(myFunction)
.build();
.default(myFunction)
.build();
```

Default exports (class)
```js
export default class MyClass {}

ESModule.export()
.default(MyClass)
.build();
.default(MyClass)
.build();
```

## Import
Expand Down Expand Up @@ -62,3 +62,36 @@ Mixed imports
import defaultExport, { MyClass, myFunction as myFunc } from "module-name";
var { defaultExport, MyClass, myFunc} = ESModule.import("default", "MyClass", "myFunction").from("module-name");
```

Import with relative and base path
```js
import defaultExport, { MyClass, myFunction as myFunc } from "module-name";
// Note: ./ and ../ are supported only at the start of the relative path. Relative paths without base path will result in error
var { myFunc} = ESModule.import("myFunction").from("../../relative/path", "module-name");
var { MyClass} = ESModule.import("MyClass").from("./relative/path", "module-name");
```

Change error handling behavior on module import/load:
```js
import defaultExport, { MyClass, myFunction as myFunc } from "module-name";
// With predefined error handling options:

// [0] DefaultModuleErrorHandlers.SYS_ERROR - Creates a System ERROR level log entry for the error. Default.
ESModule.setModuleErrorHandler(DefaultModuleErrorHandlers.SYS_ERROR);
// [1] DefaultModuleErrorHandlers.SYS_WARN - Creates a System ERROR level log entry for the error.
ESModule.setModuleErrorHandler(DefaultModuleErrorHandlers.SYS_WARN);
// [2] DefaultModuleErrorHandlers.SYS_INFO - Creates a System INFO level log entry for the error
ESModule.setModuleErrorHandler(DefaultModuleErrorHandlers.SYS_INFO);
// [3] DefaultModuleErrorHandlers.SYS_DEBUG - Creates a System DEBUG level log entry for the error
ESModule.setModuleErrorHandler(DefaultModuleErrorHandlers.SYS_DEBUG);
// [4] DefaultModuleErrorHandlers.SILENT - Ignores the error
ESModule.setModuleErrorHandler(DefaultModuleErrorHandlers.SILENT);
// [5]DefaultModuleErrorHandlers.THROW_ERROR - Rethtows the error without handling it
ESModule.setModuleErrorHandler(DefaultModuleErrorHandlers.THROW_ERROR);


// With custom error handling:
ESModule.setModuleErrorHandler(function(error) {
// custom error treatment - formatting, reporting, etc.
});
```
Loading

0 comments on commit dd57325

Please sign in to comment.