Skip to content

feat(blox-cli): strip ANSI escape sequences from stderr before error classification#416

Merged
matt2e merged 2 commits intomainfrom
re-use-code
Mar 19, 2026
Merged

feat(blox-cli): strip ANSI escape sequences from stderr before error classification#416
matt2e merged 2 commits intomainfrom
re-use-code

Conversation

@matt2e
Copy link
Contributor

@matt2e matt2e commented Mar 19, 2026

Summary

  • Add strip_ansi_escape_sequences helper that removes CSI and OSC sequences from strings
  • Apply it to stderr output before is_auth_error classification so terminal colour/style codes from sq don't break string matching
  • Fix misplaced doc comment on is_auth_error
  • Add comprehensive tests for the ANSI stripping logic

Test plan

  • Unit tests cover plain text, CSI, OSC (BEL and ST terminated), mixed sequences, empty input, and non-escape special chars
  • CI passes (crates-fmt, crates-test, crates-lint)

🤖 Generated with Claude Code

matt2e and others added 2 commits March 19, 2026 16:37
…classification

Add strip_ansi_escape_sequences() to sanitize stderr output before
passing it to is_auth_error() and before including it in
BloxError::CommandFailed. This prevents ANSI color/style codes
(CSI and OSC sequences) emitted by sq from interfering with
string-matching in error classification.

This aligns with the sanitization that was previously implemented
in the nexus repo's local copy of blox-cli.

Includes unit tests covering CSI sequences, OSC sequences (both
BEL and ST terminated), plain text passthrough, empty input, and
mixed sequences.
The doc comment for is_auth_error was incorrectly merged into the
strip_ansi_escape_sequences doc block. Move it back to is_auth_error.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@matt2e matt2e requested review from baxen and wesbillman as code owners March 19, 2026 06:17
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bee9f104b1

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +295 to +299
let stderr = strip_ansi_escape_sequences(&String::from_utf8_lossy(&stderr));
if is_auth_error(&stderr) {
return Err(BloxError::NotAuthenticated);
}
return Err(BloxError::CommandFailed(stderr.into_owned()));
return Err(BloxError::CommandFailed(stderr));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve original stderr for non-auth failures

If sq formats a non-auth error with OSC sequences (for example an OSC-8 hyperlink), this now strips that data before returning CommandFailed, so callers no longer receive the exact CLI message. That matters in the start_workspace path, which explicitly preserves the original stderr so users can see the onboarding URL/action (apps/staged/src-tauri/src/branches.rs:1251-1258). A safer change is to strip a temporary copy only for is_auth_error, while leaving the original stderr in CommandFailed.

Useful? React with 👍 / 👎.

@matt2e matt2e merged commit 51a176f into main Mar 19, 2026
6 checks passed
@matt2e matt2e deleted the re-use-code branch March 19, 2026 06:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant