Skip to content

Commit

Permalink
Fix errors when using the monorepo (#856)
Browse files Browse the repository at this point in the history
* runtime: better detection for  adaptor errors loaded from the monorepo

* runtime: relax path constraint

* changeset

* versions: [email protected] [email protected]
  • Loading branch information
josephjclark authored Jan 14, 2025
1 parent c9afba0 commit a1a071b
Show file tree
Hide file tree
Showing 16 changed files with 106 additions and 10 deletions.
7 changes: 7 additions & 0 deletions integration-tests/execute/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @openfn/integration-tests-execute

## 1.0.14

### Patch Changes

- Updated dependencies [70e3d7a]
- @openfn/runtime@1.6.1

## 1.0.13

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/execute/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@openfn/integration-tests-execute",
"private": true,
"version": "1.0.13",
"version": "1.0.14",
"description": "Job execution tests",
"author": "Open Function Group <[email protected]>",
"license": "ISC",
Expand Down
9 changes: 9 additions & 0 deletions integration-tests/worker/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# @openfn/integration-tests-worker

## 1.0.74

### Patch Changes

- Updated dependencies [70e3d7a]
- @openfn/ws-worker@1.9.1
- @openfn/engine-multi@1.4.8
- @openfn/lightning-mock@2.0.29

## 1.0.73

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/worker/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@openfn/integration-tests-worker",
"private": true,
"version": "1.0.73",
"version": "1.0.74",
"description": "Lightning WOrker integration tests",
"author": "Open Function Group <[email protected]>",
"license": "ISC",
Expand Down
8 changes: 8 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @openfn/cli

## 1.10.1

### Patch Changes

- 70e3d7a: Fix error reporting when loading adaptors from the monorepo
- Updated dependencies [70e3d7a]
- @openfn/runtime@1.6.1

## 1.10.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openfn/cli",
"version": "1.10.0",
"version": "1.10.1",
"description": "CLI devtools for the openfn toolchain.",
"engines": {
"node": ">=18",
Expand Down
7 changes: 7 additions & 0 deletions packages/engine-multi/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# engine-multi

## 1.4.8

### Patch Changes

- Updated dependencies [70e3d7a]
- @openfn/runtime@1.6.1

## 1.4.7

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/engine-multi/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openfn/engine-multi",
"version": "1.4.7",
"version": "1.4.8",
"description": "Multi-process runtime engine",
"main": "dist/index.js",
"type": "module",
Expand Down
8 changes: 8 additions & 0 deletions packages/lightning-mock/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @openfn/lightning-mock

## 2.0.29

### Patch Changes

- Updated dependencies [70e3d7a]
- @openfn/runtime@1.6.1
- @openfn/engine-multi@1.4.8

## 2.0.28

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/lightning-mock/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openfn/lightning-mock",
"version": "2.0.28",
"version": "2.0.29",
"private": true,
"description": "A mock Lightning server",
"main": "dist/index.js",
Expand Down
6 changes: 6 additions & 0 deletions packages/runtime/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @openfn/runtime

## 1.6.1

### Patch Changes

- 70e3d7a: Fix error reporting when loading adaptors from the monorepo

## 1.6.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openfn/runtime",
"version": "1.6.0",
"version": "1.6.1",
"description": "Job processing runtime.",
"type": "module",
"exports": {
Expand Down
10 changes: 7 additions & 3 deletions packages/runtime/src/execute/expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export const wrapOperation = (
try {
result = await fn(newState);
} catch (e: any) {
console.log(e);
if (e.stack) {
const containsVMFrame = e.stack.match(/at vm:module\(0\)/);

Expand All @@ -146,11 +147,14 @@ export const wrapOperation = (

let firstFrame;

// find the first error from a file or the VM
// (this cuts out low level language errors and stuff)
// find the first frame from an adaptor or the VM
// (this cuts out low level language errors like TypeError)
do {
const next = frames.shift();
if (/(@openfn\/language-)|(vm:module)/.test(next)) {
if (
// detect an adaptor prod, adaptor monorepo, or vm frame
/(@openfn\/language-)|(packages\/.+\/dist)|(vm:module)/.test(next)
) {
firstFrame = next;
break;
}
Expand Down
38 changes: 38 additions & 0 deletions packages/runtime/test/execute/wrap-operation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,41 @@ test('rethrow a job error', async (t) => {
message: 'x is not a function',
});
});

test('throw an adaptor error from a prod callstack', async (t) => {
const op = (x: any) => {
return async (_s: any) => {
// Create something that looks like an error thrown from adaptor code
const e = new TypeError('x is not a function');
e.stack = `TypeError: x is not a function
at /repo/@openfn/language-common/dist/index.cjs:573:5
at file:///repo/openfn/kit/packages/runtime/dist/index.js:649:22
at async file:///repo/openfn/kit/packages/runtime/dist/index.js:614:22;`;
throw e;
};
};

await t.throwsAsync(() => reducer([op('jam')], {}), {
name: 'AdaptorError',
message: 'x is not a function',
});
});

test('throw an adaptor error from a monorepo callstack', async (t) => {
const op = (x: any) => {
return async (_s: any) => {
// Create something that looks like an error thrown from adaptor code
const e = new TypeError('x is not a function');
e.stack = `TypeError: x is not a function
at /repo/openfn/adaptors/packages/common/dist/index.cjs:573:5
at file:///repo/openfn/kit/packages/runtime/dist/index.js:649:22
at async file:///repo/openfn/kit/packages/runtime/dist/index.js:614:22;`;
throw e;
};
};

await t.throwsAsync(() => reducer([op('jam')], {}), {
name: 'AdaptorError',
message: 'x is not a function',
});
});
9 changes: 9 additions & 0 deletions packages/ws-worker/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# ws-worker

## 1.9.1

### Patch Changes

- 70e3d7a: Fix error reporting when loading adaptors from the monorepo
- Updated dependencies [70e3d7a]
- @openfn/runtime@1.6.1
- @openfn/engine-multi@1.4.8

## 1.9.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/ws-worker/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openfn/ws-worker",
"version": "1.9.0",
"version": "1.9.1",
"description": "A Websocket Worker to connect Lightning to a Runtime Engine",
"main": "dist/index.js",
"type": "module",
Expand Down

0 comments on commit a1a071b

Please sign in to comment.