vmware / build-tools-for-vmware-aria

Build Tools for VMware Aria provides development and release management tools for implementing automation solutions based on the VMware Aria Suite and VMware Cloud Director. The solution enables Virtual Infrastructure Administrators and Automation Developers to use standard DevOps practices for managing and deploying content.
Other
48 stars 24 forks source link

VROES.import from invalid package throws Unknown error #311

Closed bcpmihail closed 3 months ago

bcpmihail commented 4 months ago

Description

When VROES.import().from() is used with invalid , it throws an Unknown error, which cannot be caught in a try/catch block (see attached screenshot).

Steps to Reproduce

  1. In the Orchestrator, create an action of the type: where "bloo" is an invalid package name
    
    var __global = System.getContext() || (function() {
    return this;
    }).call(null);
    var VROES = __global.__VROES || (__global.__VROES = System.getModule("com.vmware.pscoe.library.ecmascript").VROES);

var res; try { res = VROES.import("bla").from("bloo"); } catch (e) { throw new Error("Caught unexpected error: " + e); } return res;


2. Run the action
4. Observe the error

**Preconditions:** [What are the preconditions to reproduce the issue]

**Expected behavior:** An error with message of the type "Caught unexpected error: ..." is thrown

**Actual behavior:**  An Unknown Error is thrown - see attached screenshot:

![vroesImportUnknownError](https://github.com/user-attachments/assets/a1fb9da4-a9b6-4e14-ac1a-883877b6cffc)

**Reproduces how often:** Always.

**Component/s:** [packages/ecmascript/VROES, packages/ecmascript/Module

**Affects Build/s:** tested with 2.35.1, does not seem to have been altered since then.

### Environment

Issue found on a client environment (no longer accessible)

#### Client

-   Build Tools for VMware Aria Version: 2.35.1
-   Visual Studio Code Version: 1.89.1
-   OS Version: MacOS Ventura

#### Server

-   vRealize Automation Version: 8.16
-   vRealize Orchestrator Version: 8.16

### Failure Logs

Orchestrator logs cease at the point the Unknown error is thrown.

### Related issues and PRs

N/A

### Additional Context

https://github.com/vmware/build-tools-for-vmware-aria/blob/main/packages/ecmascript/src/Module.ts#L188 -> missing ELSE statement may be what's causing the issue.
A better approach to returning the result directly would be to store the result in a variable and throw an error if there is none in the end (preferably after try/catch, as System.getModule > module.loadModule doesn't have error handling either:
https://github.com/vmware/build-tools-for-vmware-aria/blob/main/typescript/vro-scripting-api/src/api/System.ts#L270 > https://github.com/vmware/build-tools-for-vmware-aria/blob/main/typescript/vro-scripting-api/src/modules.ts#L40
)
bcpmihail commented 4 months ago

Additional findings

Discussed with @Michaelpalacce that more specific error messages are needed, however throwing errors is a breaking change, agreed to log errors instead via System.error() by default. Implemented as additional onError parameter, providing the option to change the default behaviour (e.g. to avoid flooding the logs with Errors when trying several potential locations for an Action).