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] remove verror dependency from lib code #88

Merged
merged 2 commits into from
Dec 1, 2021

Conversation

allansson
Copy link
Contributor

The verror package used in src/errors.js has a dependency on node built-in modules, which means that the library code requires a bunch of node-polyfills to work in the browser. This PR removes that dependency by only using the verror module in bin/har-to-k6.

src/error.js Outdated
Comment on lines 1 to 9
class DetailedError extends Error {
constructor(details, message) {
super(typeof details === 'string' ? details : message)

class HarToK6Error extends VError {}
class InvalidArchiveError extends HarToK6Error {}
class UnrecognizedError extends HarToK6Error {}
if (typeof details === 'object') {
Object.assign(this, details)
}
}
}
Copy link
Contributor Author

@allansson allansson Oct 18, 2021

Choose a reason for hiding this comment

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

This error mimics the verror options object. We pass a name to the error for extra detail. I wasn't 100% certain that we always passed that object though, so I added some type checking for extra safety.

Copy link
Contributor

Choose a reason for hiding this comment

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

We pass { name: string } in every call to InvalidArchiveError and UnrecognizedError.

Comment on lines +9 to +11
const { VError } = require('verror')

class CommandLineError extends HarToK6Error {}
class CommandLineError extends VError {}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We only care about the added functionality from verror when it's a CommandLineError, so I just moved the dependency up here.

w1kman
w1kman previously approved these changes Oct 29, 2021
Copy link
Contributor

@w1kman w1kman left a comment

Choose a reason for hiding this comment

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

LGTM - Shaves off a good chunk of the bundle. 🎉

Next up moment? 🥲

@w1kman w1kman self-requested a review October 29, 2021 11:52
@w1kman w1kman dismissed their stale review October 29, 2021 11:53

HarToK6Error should still be imported.

Copy link
Contributor

@w1kman w1kman left a comment

Choose a reason for hiding this comment

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

I've re-introduced HarToK6Error for backward compatibility.

Copy link
Collaborator

@legander legander left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@EdvinasDaugirdas EdvinasDaugirdas merged commit 8ad315a into master Dec 1, 2021
@EdvinasDaugirdas EdvinasDaugirdas deleted the fix/remove-node-dependency-from-lib branch December 1, 2021 09:26
@allansson allansson mentioned this pull request Dec 1, 2021
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

4 participants