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

feat(config): improve karma.config.parseConfig error handling #3635

Merged

Conversation

npetruzzelli
Copy link
Contributor

@npetruzzelli npetruzzelli commented Jan 26, 2021

This PR add the ability of Public API users of parseConfig to opt-in to throwing errors when a critical failure is encountered.

The current behavior is to exit the process immediately, which denies the API consumer the ability to log or respond to the error at their application's level.

Related Issue: #3631

@google-cla
Copy link

google-cla bot commented Jan 26, 2021

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@npetruzzelli
Copy link
Contributor Author

Before I clean up comments and attempt to write tests for the new code, I was hoping to get feedback on this first attempt.

@AppVeyorBot
Copy link

Build karma 2885 completed (commit efd3debc07 by @npetruzzelli)

@karmarunnerbot
Copy link
Member

Build karma 488 completed (commit efd3debc07 by @npetruzzelli)

@karmarunnerbot
Copy link
Member

Build karma 487 completed (commit efd3debc07 by @npetruzzelli)

@npetruzzelli
Copy link
Contributor Author

@googlebot I signed it!

lib/utils/log-utils.js Outdated Show resolved Hide resolved
@karmarunnerbot
Copy link
Member

Build karma 489 failed (commit 2e2583226a by @npetruzzelli)

@AppVeyorBot
Copy link

Build karma 2886 failed (commit 2e2583226a by @npetruzzelli)

@karmarunnerbot
Copy link
Member

Build karma 488 failed (commit 2e2583226a by @npetruzzelli)

@karmarunnerbot
Copy link
Member

Build karma 490 completed (commit cdc64a3510 by @npetruzzelli)

@AppVeyorBot
Copy link

Build karma 2887 completed (commit cdc64a3510 by @npetruzzelli)

@karmarunnerbot
Copy link
Member

Build karma 489 completed (commit cdc64a3510 by @npetruzzelli)

@AppVeyorBot
Copy link

Build karma 2888 completed (commit 3a1cd83c70 by @npetruzzelli)

@karmarunnerbot
Copy link
Member

Build karma 490 completed (commit 3a1cd83c70 by @npetruzzelli)

@karmarunnerbot
Copy link
Member

Build karma 491 completed (commit 3a1cd83c70 by @npetruzzelli)

@npetruzzelli
Copy link
Contributor Author

npetruzzelli commented Jan 26, 2021

I wasn't sure if you intended for fail to be used outside of parseConfig. If that was the case, the signature would need only a minor change.

function fail (logArgs, failOptions) {
    const _logArgs = Array.isArray(logArgs) ? logArgs : [logArgs]
    log.error(..._logArgs )
    if (failOptions && failOptions.throwErrors === true) {
    // ...
}
// in `parseConfig`
fail (message, parseOptions)
fail ([message, e], parseOptions)

// -- OR --

function fail (logArgs, throwErrors) {
    const _logArgs = Array.isArray(logArgs) ? logArgs : [logArgs]
    log.error(..._logArgs )
    if (throwErrors === true) {
    // ...
}

// -- OR --

function fail (throwErrors, ...logArgs) {
    log.error(...logArgs )
    if (throwErrors === true) {
    // ...
}

Copy link
Collaborator

@devoto13 devoto13 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also update the usage of parseConfig in Karma's source code, so it does not rely on the deprecated behavior (last point in #3631 (comment)).

And add a unit test for parseConfig function with throwErrors: true.

Otherwise, it looks good 👍
Thanks!

lib/config.js Outdated Show resolved Hide resolved
@devoto13
Copy link
Collaborator

I wasn't sure if you intended for fail to be used outside of parseConfig. If that was the case, the signature would need only a minor change.

Good to know! Let's keep it simple here and we can adjust the signature in the next PR (if/when necessary).

@karmarunnerbot
Copy link
Member

Build karma 495 completed (commit 078db6fc9f by @npetruzzelli)

This was referenced Mar 14, 2021
@devoto13 devoto13 mentioned this pull request Mar 23, 2021
17 tasks
anthony-redFox pushed a commit to anthony-redFox/karma that referenced this pull request May 16, 2023
anthony-redFox pushed a commit to anthony-redFox/karma that referenced this pull request May 16, 2023
# [6.1.0](karma-runner/karma@v6.0.4...v6.1.0) (2021-02-03)

### Features

* **config:** improve `karma.config.parseConfig` error handling ([karma-runner#3635](karma-runner#3635)) ([9dba1e2](karma-runner@9dba1e2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants