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

refactor(lib): use assert library instead of throwing error directly #3187

Merged
merged 1 commit into from
Oct 17, 2018
Merged

refactor(lib): use assert library instead of throwing error directly #3187

merged 1 commit into from
Oct 17, 2018

Conversation

lusarz
Copy link
Contributor

@lusarz lusarz commented Oct 17, 2018

NodeJS includes assertion library natively, and it's syntax seems to be more elegant that throwing errors directly.

Copy link
Contributor

@johnjbarton johnjbarton left a comment

Choose a reason for hiding this comment

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

Does this impact the user experience? The message is similar?

@lusarz
Copy link
Contributor Author

lusarz commented Oct 17, 2018

I see message like:
assert
previously it was:
type

I think we can go one step further - wrap assert and create something like:

assertArrayWhenDefined(config.browsers, 'Invalid configuration: browsers option must be an array')

etc.

@johnjbarton What do you think ?

@johnjbarton
Copy link
Contributor

I think your change is good as is.

@lusarz
Copy link
Contributor Author

lusarz commented Oct 17, 2018

Ok.
Maybe a bit offtopic - seems like we have two different ways of processing fatal errors:

  • here we throw error out:
    assert(Array.isArray(config.browsers), 'Invalid configuration: browsers option must be an array')
  • here we log error and do process.exit :

    karma/lib/config.js

    Lines 381 to 382 in 385a0f3

    log.error('Config file must export a function!\n' + CONFIG_SYNTAX_HELP)
    return process.exit(1)

Would be nice to make it more consistent one day :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants