Skip to content

Bug: CLI logging output interferes with JSON parsing in scripts #22

@joseph-eldo

Description

@joseph-eldo

Bug: CLI logging output interferes with JSON parsing in scripts

Summary

When using slopesniper commands in shell scripts, the logging output to stderr makes it difficult to reliably parse JSON responses. This breaks automation workflows.

Environment

  • Version: 0.2.9
  • Platform: macOS (arm64)
  • Use case: Automated trading bot monitoring market cap

Problem

Commands like slopesniper price and slopesniper resolve output both:

  1. Logging messages (to stderr) - e.g., "2026-01-27 22:46:11,179 | JupiterDataClient | INFO | [get_price] Fetching price..."
  2. JSON response (to stdout) - the actual data we need

When capturing output in scripts, mixing stderr and stdout makes JSON parsing fragile and error-prone.

Example

# This should work but doesn't:
MCAP=$(slopesniper price HP9V5Un3... 2>/dev/null | jq -r '.market_cap')
# Returns empty because logging isn't suppressed

# Workaround that eventually worked:
MCAP=$(slopesniper price HP9V5Un3... 2>&1 | grep '"market_cap"' | grep -o '[0-9.]*' | head -1)
# Fragile and ugly

Full output example:

2026-01-27 22:46:11,179 | JupiterDataClient | INFO | [__init__] JupiterDataClient initialized with bundled API key
2026-01-27 22:46:11,179 | JupiterDataClient | INFO | [get_price] Fetching price for HP9V5Un3uvoex7JQEyUUSiW4yb2mRmEt9Z23axW7fLSn
2026-01-27 22:46:11,179 | JupiterDataClient | INFO | [get_prices] Fetching prices for 1 token(s)
2026-01-27 22:46:11,459 | JupiterDataClient | INFO | [get_prices] SUCCESS: Retrieved prices for 1 token(s)
2026-01-27 22:46:11,459 | JupiterDataClient | INFO | [get_price] SUCCESS: $0.00014224
2026-01-27 22:46:11,459 | JupiterDataClient | INFO | [get_token_info] Fetching info for HP9V5Un3uvoex7JQEyUUSiW4yb2mRmEt9Z23axW7fLSn
2026-01-27 22:46:11,459 | JupiterDataClient | INFO | [search_token] Searching for: HP9V5Un3uvoex7JQEyUUSiW4yb2mRmEt9Z23axW7fLSn
2026-01-27 22:46:11,722 | JupiterDataClient | INFO | [search_token] SUCCESS: Found 1 token(s)
2026-01-27 22:46:11,722 | JupiterDataClient | INFO | [get_token_info] SUCCESS: Peyote - MCap: $142,231
{
  "mint": "HP9V5Un3uvoex7JQEyUUSiW4yb2mRmEt9Z23axW7fLSn",
  "symbol": "Peyote",
  "price_usd": 0.00014224459297516187,
  "market_cap": 142231.30363850165
}

Notice how the JSON is buried in logging output.

Impact

  • Automation breaks - Can't reliably build bots/monitors
  • User experience - Scripts require hacky workarounds
  • Fragility - Any logging format change breaks parsing

Proposed Solutions

Option 1: --quiet flag (Recommended)

slopesniper price TOKEN --quiet
# Output: only JSON, no logs

Option 2: --json flag

slopesniper price TOKEN --json
# Implies quiet mode + guarantees valid JSON output

Option 3: Respect environment variable

SLOPESNIPER_QUIET=1 slopesniper price TOKEN
# Or use standard: LOG_LEVEL=ERROR

Option 4: Default behavior change

  • Keep logging as-is for interactive use
  • Auto-detect non-TTY (pipes/scripts) and suppress logs
if not sys.stdout.isatty():
    logging.disable(logging.INFO)

Use Case That Hit This

Building an auto-sell bot that monitors market cap and executes trades at a target:

while true; do
    MCAP=$(slopesniper price "$MINT" --quiet | jq -r '.market_cap')
    
    if [ "$MCAP" -ge "$TARGET" ]; then
        slopesniper sell "$MINT" all
        exit 0
    fi
    
    sleep 30
done

Without --quiet, this requires complex grep/sed gymnastics that break easily.

Related Commands Affected

All commands that output JSON should support quiet mode:

  • slopesniper price
  • slopesniper wallet
  • slopesniper status
  • slopesniper resolve
  • slopesniper check
  • slopesniper scan
  • slopesniper buy/sell (for capturing transaction results)
  • slopesniper pnl
  • slopesniper history

Additional Benefits

  • Cleaner CI/CD integration
  • Better logging control (users can choose verbosity)
  • Standard practice - most CLI tools support this pattern
  • Chainable commands - slopesniper price TOKEN --quiet | jq '.price_usd'

References

Similar patterns in other CLIs:

  • curl --silent
  • gh --jq (outputs only query result)
  • docker --quiet
  • npm --silent

Workaround (for now)

For anyone hitting this, here's the current workaround:

# Extract specific field from mixed output
VALUE=$(slopesniper price TOKEN 2>&1 | grep '"field_name"' | grep -o '[0-9.]*' | head -1)

But please add a proper --quiet flag! 🙏

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions