Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 29, 2025

The error-to-raise-arguments-error rule was incorrectly triggering on error messages where ~a appears within quotes or parentheses, like `~a' or (~a, ~a). These patterns represent literal text formatting, not argument placeholders suitable for raise-arguments-error.

Changes

  • Added validation to ensure ~a is surrounded by whitespace or at string boundaries before applying the refactoring
  • Optimized to compute regex matches once instead of twice per invocation
  • Added test cases for quoted and parenthesized ~a patterns

Examples

Now correctly skips refactoring:

;; Backticks around ~a - not refactored
(error 'find-output-radio-box "could not find `~a' radio box" label)

;; Parentheses around ~a - not refactored  
(error 'f "bad point (~a, ~a)" x y)

Still refactors when appropriate:

;; Whitespace-delimited ~a - refactored
(error 'foo "low should be less than high, ~a ~a" low high)
;; becomes:
(raise-arguments-error 'foo "low should be less than high" "low" low "high" high)
Original prompt

This section details on the original issue you should resolve

<issue_title>Unwanted suggestion from error-to-raise-arguments-error</issue_title>
<issue_description>### Problem summary

The error-to-raise-arguments-error rule shouldn't apply when the error message uses ~a under quotes, like it did in racket/drracket#779. It should only apply if all uses of ~a in the message are surrounded by spaces.

Test case for code that shouldn't be refactored

#lang resyntax/test

no-change-test: "this code should not be refactored"
--------------------
#lang racket
(define (find-output-radio-box label)
  (error 'find-output-radio-box "could not find `~a' radio box"
         label))
--------------------

Unwanted suggestion

#lang racket
(define (f label)
  (raise-arguments-error 'find-output-radio-box "could not find `' radio box" "label" label))
```</issue_description>

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

<comments>
<comment_new><author>@jackfirth</author><body>
Here's another example that shouldn't be refactored:

```scheme
#lang resyntax/test

no-change-test: "shouldn't be refactored"
--------------------
(define (f x y)
  (error 'f "bad point (~a, ~a)" x y))
--------------------
```</body></comment_new>
</comments>

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

Copilot AI changed the title [WIP] Fix unwanted suggestion from error-to-raise-arguments-error rule Fix error-to-raise-arguments-error to check ~a context Oct 29, 2025
Copilot AI requested a review from jackfirth October 29, 2025 17:25
Copilot finished work on behalf of jackfirth October 29, 2025 17:25
@coveralls
Copy link

Pull Request Test Coverage Report for Build #67

Details

  • 22 of 22 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.008%) to 93.377%

Totals Coverage Status
Change from base Build #62: 0.008%
Covered Lines: 14438
Relevant Lines: 15462

💛 - Coveralls

@jackfirth jackfirth marked this pull request as ready for review October 29, 2025 20:41
@jackfirth jackfirth merged commit 9571452 into master Oct 29, 2025
9 checks passed
@jackfirth jackfirth deleted the copilot/fix-error-to-raise-arguments-error branch October 29, 2025 20: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.

Unwanted suggestion from error-to-raise-arguments-error

3 participants