Skip to content

Add alert() and console.log() for PAC script debugging#239

Merged
manugarg merged 3 commits intomainfrom
feature/pac-logging
Apr 17, 2026
Merged

Add alert() and console.log() for PAC script debugging#239
manugarg merged 3 commits intomainfrom
feature/pac-logging

Conversation

@manugarg
Copy link
Copy Markdown
Owner

Summary

  • Expose alert(msg) and console.log(...args) in the PAC JavaScript context so authors can debug large PAC files.
  • Output is routed through the existing error printer (stderr by default, overridable via pacparser_set_error_printer), so pactester's stdout proxy result stays unaffected.
  • Messages are prefixed with ALERT: / LOG:.

Fixes #32.

Test plan

  • NO_INTERNET=1 make -C src passes (existing testdata + new end-to-end logging test in tests/runtests.sh).
  • Manually verified with pactester that logs go to stderr and proxy result stays on stdout.
  • Intentionally mutated tests/logging.pac to confirm the new check fails loudly and exits non-zero.

🤖 Generated with Claude Code

manugarg and others added 3 commits April 17, 2026 00:25
Exposes alert(msg) and console.log(...args) in the JavaScript context so
PAC authors can log from inside large PAC files. Output is routed through
the existing error printer (stderr by default, overridable via
pacparser_set_error_printer), so pactester's stdout proxy result stays
clean. Addresses #32.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Match the terse comment style of surrounding helpers (dns_resolve,
my_ip). When JS_ToCString fails mid-argument, emit a trailing newline
before returning so stderr does not carry a dangling partial line.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Extend runtests.py with a check that alert()/console.log() from a PAC
file emit the expected ALERT:/LOG: lines on stderr. Since the _pacparser
C extension writes via vfprintf on fd 2, stderr is captured at the
file-descriptor level with dup2 rather than by reassigning sys.stderr.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@manugarg manugarg merged commit b4bb053 into main Apr 17, 2026
29 of 30 checks passed
@manugarg manugarg deleted the feature/pac-logging branch April 17, 2026 07:43
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.

Add support for logging from the PAC's JavaScript

1 participant