-
Notifications
You must be signed in to change notification settings - Fork 12
Add automatic debug logging for refactoring rule pattern matching failures #600
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: jackfirth <[email protected]>
Co-authored-by: jackfirth <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds comprehensive automatic debug logging for refactoring rule pattern matching failures to help developers debug issues in #lang resyntax/test
. The logging provides detailed information about why rules don't match by tracking #:with
expression errors and rule match discards.
Key changes:
- Automatic wrapping of
#:with
expressions with error handling and logging - Automatic addition of
#:undo
directives to log when partial matches are discarded - Extension of existing
#:when
condition logging infrastructure
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
private/logger.rkt | Adds new logging functions for #:with expressions and undo operations |
base.rkt | Modifies refactoring rule macros to automatically wrap directives and add logging |
(begin | ||
(define temp-result | ||
(with-handlers ([exn:fail? (λ (e) | ||
(log-resyntax-debug "rule #:with expression ~a failed with error: ~a on line ~a" | ||
'expr (exn-message e) 'line) | ||
(raise e))]) | ||
expr)) | ||
temp-result)) |
Copilot
AI
Sep 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The temporary variable temp-result
is unnecessary. You can directly return the result of the with-handlers
expression to simplify the code.
(begin | |
(define temp-result | |
(with-handlers ([exn:fail? (λ (e) | |
(log-resyntax-debug "rule #:with expression ~a failed with error: ~a on line ~a" | |
'expr (exn-message e) 'line) | |
(raise e))]) | |
expr)) | |
temp-result)) | |
(with-handlers ([exn:fail? (λ (e) | |
(log-resyntax-debug "rule #:with expression ~a failed with error: ~a on line ~a" | |
'expr (exn-message e) 'line) | |
(raise e))]) | |
expr)) |
Copilot uses AI. Check for mistakes.
|
||
|
||
(require (for-syntax racket/base) | ||
rebellion/base/option |
Copilot
AI
Sep 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rebellion/base/option
module is imported but not used in any of the new code. This import should be removed unless it's used elsewhere in the file.
rebellion/base/option |
Copilot uses AI. Check for mistakes.
This PR implements comprehensive automatic debug logging for refactoring rules to make debugging
#lang resyntax/test
failures much easier. The logging provides detailed information about why rules don't match, complementing the existing partial match and#:when
condition logging.Changes Made
New Debug Logging Features
#:with Expression Logging: Automatically wraps
#:with
expressions to log when they fail with errors during evaluation. This helps identify when expressions in#:with
directives throw exceptions or produce unexpected results.#:undo Directive Logging: Automatically adds
#:undo
directives to every refactoring rule that log when partial rule matches are discarded for any reason. This provides visibility into when rules match initially but then fail due to subsequent pattern directives.Implementation Details
Automatic wrapping: The
define-refactoring-rule
anddefine-definition-context-refactoring-rule
macros now automatically:#:when
conditions with logging (existing functionality)#:with
expressions with error handling and logging (new)#:undo
directives that log when partial matches are discarded (new)Debug level logging: All new logging uses the debug level, so it's only visible when debug logging is enabled with
PLTSTDERR="debug@resyntax"
Compatible with existing infrastructure: The
#lang resyntax/test
language automatically captures debug logs, making test failures much easier to diagnoseExample Output
When a rule fails to match, you now see detailed logging like:
This shows the progression from initial pattern match → condition failure → rule discard, making it much clearer why a rule didn't apply to specific code.
Testing
define-contract-struct-migration
Fixes #599.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.