Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 1, 2025

All CLI output including errors was going to stdout, making it impossible to separate error handling from normal output in scripts.

Changes

  • Replace panic() with fmt.Fprintf(os.Stderr, ...) for file read errors
  • Change fmt.Printf() to fmt.Fprintf(os.Stderr, ...) for parse errors

Usage

# Errors now visible when stdout is suppressed
clickhouse-sql-parser -f schema.sql -format 1>/dev/null
# read file error: open schema.sql: no such file or directory

# Separate error logging
clickhouse-sql-parser "SELECT * FROM t" 2>errors.log
Original prompt

This section details on the original issue you should resolve

<issue_title>Cannot separate stderr from stdout — all output goes to stdout</issue_title>
<issue_description>Description:

I'm encountering an issue with the clickhouse-sql-parser tool where it's impossible to properly separate error output (stderr) from standard output (stdout). Currently, all messages (including error messages) are being directed to stdout, which prevents proper error handling and logging.

Expected behavior:

  • Error messages should be printed to stderr, index 2.
  • Regular (non‑error) output should go to stdout, index 1.
  • This would allow users to:
    • Suppress normal output while still seeing errors (e.g., using 1>/dev/null).
    • Redirect errors to log files separately from regular output.
    • Implement proper error detection in scripts (e.g., checking exit codes and error streams).

Actual behavior:

All output (including error messages) is being sent to stdout, making it impossible to distinguish between normal operation and error conditions without parsing the output content.

Example:

When running:

clickhouse-sql-parser \
    -f ${SCHEMA_FILE} \
    -format 1>/dev/null

Even if an error occurs (e.g., file not found, syntax error), the error message is still sent to stdout and gets suppressed by the redirection (1>/dev/null), so the user doesn't see any indication that something went wrong.

Impact:

  • Inability to implement proper error handling in automation scripts.
  • Difficulty in monitoring and logging errors separately from normal output.
  • Potential for silent failures in automated workflows.

Proposed solution:
Redirect error messages and warnings to stderr instead of stdout, following standard UNIX/Linux conventions for command‑line tools.

Environment:

  • Tool: clickhouse-sql-parser
  • OS: MacOS (arm64)
  • Version: v0.3.8
    </issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: git-hulk <4987594+git-hulk@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix error output routing in clickhouse-sql-parser Fix: Send error messages to stderr instead of stdout Dec 1, 2025
Copilot AI requested a review from git-hulk December 1, 2025 08:59
Copilot finished work on behalf of git-hulk December 1, 2025 08:59
@git-hulk git-hulk marked this pull request as ready for review December 1, 2025 09:35
@git-hulk git-hulk merged commit fd7b5d0 into master Dec 1, 2025
3 checks passed
@coveralls
Copy link

Pull Request Test Coverage Report for Build 19816848514

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 51.054%

Totals Coverage Status
Change from base Build 19558226329: 0.0%
Covered Lines: 7943
Relevant Lines: 15558

💛 - Coveralls

@coveralls
Copy link

Pull Request Test Coverage Report for Build 19816848795

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 51.054%

Totals Coverage Status
Change from base Build 19558226329: 0.0%
Covered Lines: 7943
Relevant Lines: 15558

💛 - Coveralls

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.

Cannot separate stderr from stdout — all output goes to stdout

3 participants