Inspector command failed
Production Risk
Low — inspector usage is confined to development and profiling tools.
Thrown when a command sent via inspector.Session.post() fails. The error contains the error code and message returned by the Chrome DevTools Protocol. Common causes include invalid method names, wrong parameters, or calling commands in an invalid order.
- 1Sending an invalid Chrome DevTools Protocol method name
- 2Providing incorrect or missing parameters for a CDP command
- 3Calling a CDP domain command before enabling the domain
Triggered when a CDP command sent via session.post() returns an error response.
const inspector = require('inspector');
const session = new inspector.Session();
session.connect();
session.post('Runtime.unknownMethod', {}, (err) => {
if (err) console.error(err.code); // ERR_INSPECTOR_COMMAND
});expected output
Error [ERR_INSPECTOR_COMMAND]: Inspector error code: -32601 - Method not found
Fix 1
Enable the CDP domain before calling its methods
WHEN When using CDP domains that require explicit enabling
session.post('Profiler.enable', {}, () => {
session.post('Profiler.start', {}, () => {
// profiling is now active
});
});Why this works
CDP domains must be enabled before their methods can be called; enabling first prevents command errors.
Fix 2
Handle command errors in the callback
WHEN For all session.post() calls
session.post('Runtime.evaluate', { expression: '1+1' }, (err, result) => {
if (err) {
console.error('CDP command failed:', err.message);
return;
}
console.log(result.result.value); // 2
});Why this works
Checking the err argument in the callback allows graceful handling of CDP failures.
const inspector = require('inspector');
const session = new inspector.Session();
session.connect();
session.post('Runtime.unknownMethod', {}, (err) => {
if (err) console.error(err.code); // ERR_INSPECTOR_COMMAND
}); // this triggers ERR_INSPECTOR_COMMANDtry {
// operation that may throw ERR_INSPECTOR_COMMAND
riskyOperation()
} catch (err) {
if (err.code === 'ERR_INSPECTOR_COMMAND') {
console.error('ERR_INSPECTOR_COMMAND:', err.message)
} else {
throw err
}
}// Validate inputs before calling the operation
function safe_err_inspector_command(...args) {
// validate args here
return performOperation(...args)
}✕ Ignore the error argument in session.post() callbacks
CDP command failures are only reported via the error callback; ignoring them hides bugs.
Node.js Error Codes Documentation
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev