Repository navigation
fix: print the token path with ~, and colour errors by stderr - #175
Conversation
doctor shortened the path with homePath (#130); the client's TOKEN_MISSING and multi-line TOKEN_INVALID messages printed it in full. README's error table now shows the short form. Closes #146 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018qh9xqviBHYmzVtmQWSKqA
apply-color-mode decides chalk's level from stdout, so with stdout on a terminal and stderr redirected the error envelope carried ANSI codes into the file. formatError now asks shouldDisableColor about stderr, the stream it writes to, as the hint wrap already measures stderr's width. Closes #150 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018qh9xqviBHYmzVtmQWSKqA
|
Codex review ( Reviewed The two touched test files passed: 53 tests, 0 failures. Simplification: not needed Verdict: Approve |
[Medium impact] The PR appears safe to merge, with one non-blocking test gap from the previous review. Findings
SummaryThe PR shortens home-directory token paths in errors and prevents colour codes in redirected stderr.
Reviews (2) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." · Reviewed by Greptile |
| expect(formatError(new CliError('BAD_ARGS', 'boom'), 'table', undefined, false).text).toBe('error: boom'); | ||
| expect(formatError(new CliError('BAD_ARGS', 'boom'), 'table', undefined, true).text).toBe('\u001b[31merror: boom\u001b[39m'); |
There was a problem hiding this comment.
Both calls pass colour explicitly, so neither checks the stderr-based default that fixes #150. Changing process.stderr.isTTY back to process.stdout.isTTY would leave this test passing. Add a test with different stdout and stderr TTY states, and omit the fourth argument.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
# Conflicts: # CHANGELOG.md
Closes #146, closes #150.
What
TOKEN_MISSINGfromsyncandfetchnames the token file with~(No Oura access token at ~/.oura-token.), through the samehomePaththatdoctoruses. The multi-line token error (TOKEN_INVALID) names the file the same way. README's error table now shows the short form. (Token path:doctorprints~/.oura-token,sync/fetchTOKEN_MISSING print the full home path #146)formatErrorcolours theerror:line only when stderr would take colour:shouldDisableColorapplied to stderr's TTY state, soNO_COLOR,--no-colorandFORCE_COLORkeep their meaning. Before this, chalk's level followed stdout alone. (Error colour follows stdout, not stderr:sync 2>err.logon a terminal writes ANSI into the file #150)Why
Both reproduced on main:
syncprintedNo Oura access token at /Users/<name>/.oura-token.whiledoctorprinted~/.oura-token.script -q /dev/null bash -c 'oura-cli sync 2>err.log'(stdout a pty, stderr a file) left^[[31merror: …^[[39minerr.log. After the fix the file holds plain text, and a pty on both streams is still red.How checked
src/api/client.test.ts(a token path under the home directory that does not exist; exact message) andsrc/lib/errors.test.ts(chalk forced on; exact text withcolourfalse and true).doctorprints~/.oura-token,sync/fetchTOKEN_MISSING print the full home path #146:`No Oura access token at ${homePath(source)}.`→`No Oura access token at ${source}.`inclient.ts: 1 of 35 fails (the new test).sync 2>err.logon a terminal writes ANSI into the file #150:const head = colour ? chalk.red(`error: ${message}`) : `error: ${message}`;→const head = chalk.red(`error: ${message}`);inerrors.ts: 1 of 18 fails (the new test).bun run check: typecheck, Biome, Knip clean; 713 tests pass.🤖 Generated with Claude Code
https://claude.ai/code/session_018qh9xqviBHYmzVtmQWSKqA