Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VROES.import from invalid package throws Unknown error #311

Closed
bcpmihail opened this issue Jul 11, 2024 · 1 comment · Fixed by #345
Closed

VROES.import from invalid package throws Unknown error #311

bcpmihail opened this issue Jul 11, 2024 · 1 comment · Fixed by #345
Assignees
Labels
area/ecmascript Relates to ecmascript module effort/medium kind/bug Something isn't working lang/typescript Related to typescript code priority/medium triage/accepted The issue was accepted and will be done

Comments

@bcpmihail
Copy link
Contributor

bcpmihail commented Jul 11, 2024

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;
  1. Run the action
  2. 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

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 bcpmihail added kind/bug Something isn't working lang/typescript Related to typescript code area/ecmascript Relates to ecmascript module labels Jul 11, 2024
@Michaelpalacce Michaelpalacce added triage/needed Needs to be discussed by project maintainers triage/accepted The issue was accepted and will be done and removed triage/needed Needs to be discussed by project maintainers labels Jul 11, 2024
@bcpmihail bcpmihail self-assigned this Jul 11, 2024
@bcpmihail
Copy link
Contributor Author

Additional findings

  • System.getModule() doesn't work with undefined (throwing a Java error).
  • Trying to load a module with empty path causes an issue.
    Findings in Module.ts:
  • Module.export(path) => path parameter is unused, removed from interface.
  • Module.export().from(...) => from() not path of interface, marked deprecated for future removal. No path validations will be implemented for this method.

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).

bcpmihail added a commit that referenced this issue Aug 19, 2024
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/ecmascript Relates to ecmascript module effort/medium kind/bug Something isn't working lang/typescript Related to typescript code priority/medium triage/accepted The issue was accepted and will be done
Projects
None yet
2 participants