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

fix: log worker errors instead of crash #559

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .freeCodeCamp/tooling/tests/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ export async function runTests(ws, projectDashedName) {
WORKER_POOL.push(worker);

// When result is received back from worker, update the client state
worker.on('error', workerError);
worker.on('message', workerMessage);
worker.on('messageerror', workerError);
worker.stdout.on('data', data => {
logover.debug(`Blocking Worker:`, data.toString());
});
Expand Down Expand Up @@ -121,7 +123,9 @@ export async function runTests(ws, projectDashedName) {
WORKER_POOL.push(worker);

// When result is received back from worker, update the client state
worker.on('error', workerError);
worker.on('message', workerMessage);
worker.on('messageerror', workerError);
worker.stdout.on('data', data => {
logover.debug(`Worker-${i}:`, data.toString());
});
Expand Down Expand Up @@ -176,6 +180,10 @@ export async function runTests(ws, projectDashedName) {
afterAll
});
}

async function workerError(error) {
logover.error(`Worker Error:`, error);
}
} catch (e) {
logover.error('Test Error: ');
logover.error(e);
Expand Down
14 changes: 14 additions & 0 deletions self/curriculum/locales/english/build-x-using-y.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ await new Promise(resolve => setTimeout(resolve, 1000));
assert.equal(__helpers.testDynamicHelper(), 'Helper success!');
```

Testing if a worker error causes the server to crash.

```js
// 3
try {
fetch('http://localhost:3123');
} catch (e) {
console.log('------test------');
console.log(e);
console.log('------test------');
assert.equal(e.message, 'Failed to fetch');
}
```

### --before-each--

```js
Expand Down