Skip to content

Commit

Permalink
Throw error if tc interface retrieval fails (#56)
Browse files Browse the repository at this point in the history
* Throw error if tc interface retrieval fails

On Linux if `net-tools` are not installed `tc` will fail to get the default interface using the `route` command. Or it might fail for any other reason.

This commit adds a safeguard to bug out on err and displays the actual stderr received instead of hiding it.
  • Loading branch information
radum authored Mar 19, 2021
1 parent ee32a5b commit fede6e8
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/tc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ async function getDefaultInterface() {
"sudo route | grep '^default' | grep -o '[^ ]*$' | tr -d '\n'",
{ shell: true }
);

if (result.stdout.length === 0 && result.stderr.length > 0) {
throw new Error(
'There was an error getting the default interface:\n\n' + result.stderr
);
}

return result.stdout;
}

Expand Down

0 comments on commit fede6e8

Please sign in to comment.