Skip to content

Commit

Permalink
Merge pull request #728 from OpenFn/better-error-serializing
Browse files Browse the repository at this point in the history
Runtime: better errors
  • Loading branch information
josephjclark authored Jul 5, 2024
2 parents b03f622 + 047725c commit a3cbb38
Show file tree
Hide file tree
Showing 31 changed files with 245 additions and 146 deletions.
12 changes: 3 additions & 9 deletions integration-tests/cli/test/execute-workflow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,10 @@ test.serial(
},
errors: {
start: {
error: {
message: 'abort',
type: 'JobError',
name: 'JobError',
severity: 'fail',
source: 'runtime',
},
stepId: 'start',
source: 'runtime',
name: 'JobError',
severity: 'fail',
message: 'abort',
type: 'JobError',
},
},
});
Expand Down
10 changes: 10 additions & 0 deletions integration-tests/worker/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# @openfn/integration-tests-worker

## 1.0.50

### Patch Changes

- Updated dependencies [afcd041]
- Updated dependencies [afcd041]
- @openfn/engine-multi@1.1.13
- @openfn/ws-worker@1.3.0
- @openfn/lightning-mock@2.0.13

## 1.0.49

### 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.49",
"version": "1.0.50",
"description": "Lightning WOrker integration tests",
"author": "Open Function Group <[email protected]>",
"license": "ISC",
Expand Down
11 changes: 11 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# @openfn/cli

## 1.5.0

### Minor Changes

- Better error reporting in logs and on final state

### Patch Changes

- Updated dependencies [afcd041]
- @openfn/runtime@1.4.0

## 1.4.2

### Patch 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.4.2",
"version": "1.5.0",
"description": "CLI devtools for the openfn toolchain.",
"engines": {
"node": ">=18",
Expand Down
10 changes: 10 additions & 0 deletions packages/engine-multi/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# engine-multi

## 1.1.13

### Patch Changes

- afcd041: Remove the type key from errors
- Updated dependencies [afcd041]
- Updated dependencies [afcd041]
- @openfn/runtime@1.4.0
- @openfn/lexicon@1.0.2

## 1.1.12

### 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.1.12",
"version": "1.1.13",
"description": "Multi-process runtime engine",
"main": "dist/index.js",
"type": "module",
Expand Down
8 changes: 1 addition & 7 deletions packages/engine-multi/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export class EngineError extends Error {
// It is generated by workerpool and thrown if the workerpool promise fails to resolve
export class TimeoutError extends EngineError {
severity = 'kill';
type = 'TimeoutError';
name = 'TimeoutError';
duration;
constructor(durationInMs: number) {
Expand All @@ -28,7 +27,6 @@ export class TimeoutError extends EngineError {
// This is a catch-all error thrown during execution
export class ExecutionError extends EngineError {
severity = 'exception';
type = 'ExecutionError';
name = 'ExecutionError';
message;

Expand All @@ -45,7 +43,7 @@ export class ExecutionError extends EngineError {

export class CompileError extends EngineError {
severity = 'crash'; // Syntax errors are crashes, but what if we get a module resolution thing?
type = 'CompileError';
name = 'CompileError';
subtype;
message;
jobId;
Expand All @@ -61,7 +59,6 @@ export class CompileError extends EngineError {

export class AutoinstallError extends EngineError {
severity = 'exception'; // Syntax errors are crashes, but what if we get a module resolution thing?
type = 'AutoinstallError';
name = 'AutoinstallError';
message;

Expand All @@ -74,7 +71,6 @@ export class AutoinstallError extends EngineError {

export class OOMError extends EngineError {
severity = 'kill';
type = 'OOMError';
name = 'OOMError';
message;

Expand All @@ -87,7 +83,6 @@ export class OOMError extends EngineError {

export class ExitError extends EngineError {
severity = 'crash';
type = 'ExitError';
name = 'ExitError';
code;
message;
Expand All @@ -107,7 +102,6 @@ export type CredentialErrorObj = { id: string; step: string; error: string };
// Error lazy-loading a credenial
export class CredentialLoadError extends EngineError {
severity = 'exception';
type = 'CredentialLoadError';
name = 'CredentialLoadError';
message;

Expand Down
2 changes: 1 addition & 1 deletion packages/engine-multi/src/util/serialize-error.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export default (error: any) => {
return {
message: error.message,
type: error.subtype || error.type || error.name,
name: error.subtype || error.type || error.name,
severity: error.severity || 'crash',
};
};
2 changes: 1 addition & 1 deletion packages/engine-multi/src/worker/pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ function createPool(script: string, options: PoolOptions = {}, logger: Logger) {
const e = new Error(evt.error.message);
// @ts-ignore
e.severity = evt.error.severity;
e.name = evt.error.type;
e.name = evt.error.name;
reject(e);

finish(worker);
Expand Down
2 changes: 1 addition & 1 deletion packages/engine-multi/test/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ test.serial('errors get nicely serialized', (t) => {
]);

api.execute(plan, emptyState).on('job-error', (evt) => {
t.is(evt.error.type, 'TypeError');
t.is(evt.error.name, 'TypeError');
t.is(evt.error.severity, 'fail');
t.is(
evt.error.message,
Expand Down
6 changes: 6 additions & 0 deletions packages/lexicon/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# lexicon

## 1.0.2

### Patch Changes

- afcd041: Add type for SerializedErrors and deprecate ErrorReport

## 1.0.1

### Patch Changes
Expand Down
20 changes: 19 additions & 1 deletion packages/lexicon/core.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export declare interface State<S = object, C = object> {
// Core state props used by the runtime
configuration?: C;
data?: S;
errors?: Record<StepId, ErrorReport>;
errors?: Record<StepId, SerializedError>;

// Props added by common
references?: Array<any>;
Expand Down Expand Up @@ -131,6 +131,24 @@ export interface Trigger extends Step {}
*/
export type CompiledExpression = Expression;

/**
* This is what serialized error objects should look like
* This is not well enforced right now
*/
export type SerializedError = {
source: string;
name: string;
severity: string;
message: string;
details: any;

stack?: string;
position?: string;
};

/**
* @deprecated
*/
export type ErrorReport = {
type: string; // The name/type of error, ie Error, TypeError
message: string; // simple human readable message
Expand Down
2 changes: 1 addition & 1 deletion packages/lexicon/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openfn/lexicon",
"version": "1.0.1",
"version": "1.0.2",
"description": "Central repo of names and type definitions",
"author": "Open Function Group <[email protected]>",
"license": "ISC",
Expand Down
11 changes: 11 additions & 0 deletions packages/lightning-mock/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# @openfn/lightning-mock

## 2.0.13

### Patch Changes

- Updated dependencies [afcd041]
- Updated dependencies [afcd041]
- Updated dependencies [afcd041]
- @openfn/runtime@1.4.0
- @openfn/lexicon@1.0.2
- @openfn/engine-multi@1.1.13

## 2.0.12

### 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.12",
"version": "2.0.13",
"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.4.0

### Minor Changes

- afcd041: Refactor of error objects for better serialization in worker and CLI

## 1.3.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.3.0",
"version": "1.4.0",
"description": "Job processing runtime.",
"type": "module",
"exports": {
Expand Down
Loading

0 comments on commit a3cbb38

Please sign in to comment.