`--latest` option triggers network request even for `--help` and `--version` commands
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- javascript
- Domain
- cli
Research direction
Start in src/eoc.js:115-119 and inspect the existing preAction hook around line 159, then trace how program.opts().parser is consumed and how help/version bypass command hooks. Move latest-version resolution out of module loading so those commands make no network request, and verify failures occur only for commands that build.
Written by the indexing model from the issue text.
Description
What happens
--latest fetches from Maven Central while src/eoc.js is still being loaded, before commander has looked at the command line. So eoc --latest --help and eoc --latest --version both block on a network request, and fail with a network error when there is none.
src/eoc.js:115-119:
let parser = fs.readFileSync(path.join(__dirname, '../eo-version.txt'), 'utf8').trim();
if (process.argv.includes('--latest')) {
parser = require('./parser-version').get();
This is module scope, not a command action. It runs on import, so it runs for every invocation whose argv contains --latest, whatever the rest of the line says — including the two that produce no build at all.
The request is synchronous. parser-version.get() uses sync-request with timeout: 100000, socketTimeout: 100000, so an unreachable or slow repository stalls the process for up to a hundred seconds with nothing printed, since the console.info naming the version comes after the call returns.
Offline, it does not stall, it fails. get() throws on any non-200, and a failure to connect propagates out of a module-level statement, which means the process dies before commander is reached and before program.parseAsync could have turned it into the message on src/eoc.js:459-461. Asking eoc --latest --help what the flags are is not a request that should need the network at all.
process.argv.includes('--latest') is doing option parsing by hand, in a file that has commander configured a few lines below. It also matches the string anywhere on the line, so an object argument that happens to be --latest triggers the fetch too.
Suggested fix
Resolve the version where it is needed rather than where the module loads. The value is only consumed through program.opts().parser, so a preAction hook — the file already has one on src/eoc.js:159 for --dir — is the natural place:
program.hook('preAction', (command) => {
if (command.opts().latest) {
command.setOptionValue('parser', require('./parser-version').get());
}
});
--help and --version never reach a hook, so both stop touching the network, and a failure to reach Maven Central becomes an error from a command that was actually asked to build something.
Worth reconsidering sync-request at the same time. It is deprecated and it blocks the event loop for the whole timeout; the rest of the file is already async, and get() has exactly one caller.
- Dominant language
- JavaScript
- Stars
- 36
- Forks
- 64
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 17
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from objectionary/eoc
-
bug good-title
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
objectionary/eoc#1360 ·
-
bug good-title
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
objectionary/eoc#1359 ·
-
bug good-title
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
objectionary/eoc#1358 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
objectionary/eoc#1357 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
objectionary/eoc#1356 ·
All issues in objectionary/eoc
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
HarperFast/skills#96 ·
-
[Block] Latest Posts [Type] Bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Automattic/studio#4908 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
sugarlabs/musicblocks#8847 ·