#94: Add timestamps for maven logs#955
Conversation
|
@nacNAC333 Thanks for your contribution! Unfortunately, we can't merge it without tests. Every feature we add and every bug we fix must be accompanied by at least one new test that confirms that the code was not working before. Without such a test, how can we know that what you commit actually works? |
Favixx
left a comment
There was a problem hiding this comment.
mvnw crashes on every invocation — result.stderr is null
This change makes the mvnw wrapper throw a TypeError on every call, so effectively every eoc command (parse, compile, etc.) fails before Maven even starts.
Setting stdio: ['pipe', 'pipe', 'inherit'] inherits the child's stderr, which means child.stderr is null. The handler added below then dereferences it.
Reproduced on this branch with a minimal call mvnw(['--version']):
TypeError: Cannot read properties of null (reading 'on')
at src/mvnw.js:127:19
at new Promise (<anonymous>)
The same call on master runs to completion, so the regression is introduced here.
Additional notes:
- Reformatting Maven output line-by-line in JS is lossy (see inline comments). A native approach via slf4j-simple flags (
-Dorg.slf4j.simpleLogger.showDateTime=true/-Dorg.slf4j.simpleLogger.dateTimeFormat=...), as in #964/#909, lets Maven emit timestamps itself and preserves formatting. - Per project policy, please add a test that fails before this change and passes after — none of the current tests exercise the spawn path, which is why this crash was not caught.
| { | ||
| cwd: home, | ||
| stdio: 'inherit', | ||
| stdio: ['pipe', 'pipe', 'inherit'], |
There was a problem hiding this comment.
['pipe', 'pipe', 'inherit'] means stdin=pipe, stdout=pipe, stderr=inherit. With stderr inherited, child.stderr is null, which makes the result.stderr.on(...) handler below throw. Two separate problems here:
- To pipe both stdout and stderr (so you can prefix them), use
['inherit', 'pipe', 'pipe']and attach handlers to both. - Changing stdin from the previous
inherittopipealso detaches the child from the terminal, which can break interactive prompts.
| } | ||
| } | ||
| }); | ||
| result.stderr.on('data', (chunk) => { |
There was a problem hiding this comment.
Crash site. Because stderr is inherited above, result.stderr is null, so this line throws TypeError: Cannot read properties of null (reading 'on') synchronously, before Maven runs. Verified with mvnw(['--version']) on this branch:
TypeError: Cannot read properties of null (reading 'on')
at src/mvnw.js:127:19
Either pipe stderr in the stdio array, or drop this handler if stderr is meant to stay inherited.
| shell: shell(), | ||
| } | ||
| ); | ||
| result.stdout.on('data', (chunk) => { |
There was a problem hiding this comment.
Two issues with the line-by-line reformatting:
line.trim()strips Maven's indentation and collapses whitespace, so structured output (e.g. nested reactor logs) is mangled.- A
datachunk is not guaranteed to align to line boundaries — a chunk can split a line mid-way, sosplit(' ')per chunk will timestamp partial lines and concatenate them incorrectly. Buffer until a newline (e.g.readline.createInterface) if you keep this approach.
|
@yegor256 Test added — |
Fixes #94
Add timestamps to Maven log output for easier debugging.
Changes to src/mvnw.js: