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

command’s error handling and asynchronous flow rely on callbacks. #4365

Open
imramkrishna opened this issue Feb 2, 2025 · 1 comment · May be fixed by #4366
Open

command’s error handling and asynchronous flow rely on callbacks. #4365

imramkrishna opened this issue Feb 2, 2025 · 1 comment · May be fixed by #4366

Comments

@imramkrishna
Copy link

imramkrishna commented Feb 2, 2025

Description

File: lib/api/client-commands/enablePerformanceMetrics.js

Currently, the command’s error handling and asynchronous flow rely on callbacks. Refactoring the performAction method to use async/await can simplify the logic and provide more consistent promise-based error handling. This update would both improve readability and make it easier to maintain.

Image

Suggested solution


// Wrap the callback-based transport action in a promise

class EnablePerformanceMetrics extends ClientCommand {
async performAction() {
if (!this.api.isChrome() && !this.api.isEdge()) {
const error = new Error('The command .enablePerformanceMetrics() is only supported in Chrome and Edge drivers');
Logger.error(error);
throw error;
}
const { enable = true } = this;
return new Promise((resolve, reject) => {
this.transportActions.enablePerformanceMetrics(enable, (err, result) => {
if (err) {
return reject(err);
}
resolve(result);
});
});
}

async command(enable) {
this.enable = enable;
// Assuming super.command now returns a promise
return await super.command();
}
}

module.exports = EnablePerformanceMetrics;


Alternatives / Workarounds

No response

Additional Information

No response

@toffee-k21
Copy link

Hey @imramkrishna,
I think this should be implemented across the entire repository rather than just for lib/api/client-commands/enablePerformanceMetrics.js

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

Successfully merging a pull request may close this issue.

2 participants