Skip to content

fix: write errors to stdout when using -jsonl flag#1524

Open
buildingvibes wants to merge 1 commit intoprojectdiscovery:devfrom
buildingvibes:fix-jsonl-headless-error
Open

fix: write errors to stdout when using -jsonl flag#1524
buildingvibes wants to merge 1 commit intoprojectdiscovery:devfrom
buildingvibes:fix-jsonl-headless-error

Conversation

@buildingvibes
Copy link

@buildingvibes buildingvibes commented Feb 9, 2026

Summary

Root Cause

The WriteErr method in pkg/output/output.go was only writing errors to the error file (if configured) but not to stdout, even when -jsonl flag was used. This caused inconsistent output behavior where normal results were written to stdout but errors were not.

Solution

Modified WriteErr to check if JSON output mode is enabled (w.json). When true, errors are now written to:

  1. stdout via gologger.Silent().Msgf()
  2. The output file (if configured)
  3. The error file (if configured)

This ensures consistent behavior with the Write method which already outputs to stdout in JSON mode.

Test Results

Before Fix

echo "https://projectdiscovery.io" | katana -silent -d 1 -jsonl -ob -or -headless
# Would show timeout errors like:
# {"timestamp":"...","request":{"method":"GET","endpoint":"..."},"error":"[hybrid:RUNTIME] context deadline exceeded <- could not get dom"}

After Fix

echo "https://projectdiscovery.io" | katana -silent -d 1 -jsonl -ob -or -headless
# Now successfully outputs JSON results:
{"request":{"method":"GET","endpoint":"https://projectdiscovery.io/","tag":"a","attribute":"href","source":"https://projectdiscovery.io/"}}
{"request":{"method":"GET","endpoint":"https://projectdiscovery.io/request-demo","tag":"a","attribute":"href","source":"https://projectdiscovery.io/"}}
# ... (more results)

Backward Compatibility Verified

  • Non-JSON mode still works correctly
  • All existing tests pass
  • Error file writing behavior unchanged

/claim #611

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Fixed inconsistent JSON error output formatting to match standard output behavior. Error data is now properly written to configured output destinations.

Fixes projectdiscovery#611

When using -jsonl with -headless, errors were not being written to stdout,
causing the output to be incomplete. This fix ensures that when JSON output
is enabled, errors are written to stdout in addition to the error file
(if configured), maintaining consistency with normal result output.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 9, 2026

Walkthrough

The WriteErr function in the output module is updated to ensure JSON error data is written to stdout and the configured output file when JSON output is enabled, maintaining consistency with the non-error output path. The change also wraps write errors appropriately.

Changes

Cohort / File(s) Summary
Error Output Handling
pkg/output/output.go
Modified WriteErr to write JSON error data to stdout and output file when JSON output is enabled, mirroring behavior from non-error paths. Added error handling for output file writes.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Poem

🐰 When errors arose with headless crawls,
The JSON output fell through the walls,
A simple fix, a mirror so bright,
Now errors flow true, and all feels right!
✨🔧

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the fix: writing errors to stdout when using the -jsonl flag. It directly reflects the main change in the changeset.
Linked Issues check ✅ Passed The PR successfully implements the fix for issue #611 by ensuring WriteErr writes JSON-formatted errors to stdout when JSON output mode is enabled, matching expected behavior.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the stated issue; no unrelated modifications detected in the output file handling.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@buildingvibes
Copy link
Author

I've closed my other PRs to focus on this one per project contribution guidelines.

Copy link
Member

@dwisiswant0 dwisiswant0 left a comment

Choose a reason for hiding this comment

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

How does adding new writer solve the underlying context deadline issue?

@tarunKoyalwar tarunKoyalwar removed their request for review February 17, 2026 14:50
Copy link
Member

@Mzack9999 Mzack9999 left a comment

Choose a reason for hiding this comment

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

As @dwisiswant0 pointed out, the issue seems related to a rot context handling

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

-jsonl option with -headless option results in error

3 participants