@xlambein Also keep in mind that ...
means zero or more. Instead you might want ...+
which means one or more.: https://docs.racket-lang.org/syntax/stxparse-patterns.html#%28form._%28%28lib._syntax%2Fparse..rkt%29._......%2B%29%29
IIRC ...+
is only available from syntax-parse
.
While using racket/gui I’ve noticed that some runtime contract errors often don’t get printed. It seems to happen when the error occurs while instantiating a class. Any idea what is happening here? It makes it somewhat difficult to debug simple runtime errors. I’m using racket-mode and these messages would normally be printed to the REPL buffer.
Off the top of my head I’m not sure. Would it be possible for you to give me e.g. a single .rkt
file example that, when run, shows the problem? (I mean, causes a runtime error, but you don’t see any error message displayed.)
Also what do you have (in Emacs) for racket-error-context
? If it is low
or medium
, does the problem go away if you choose high
? Or vice versa?
I tried this: #lang racket/gui
(define frame (new frame%
[label 9999999999999]
[height 512]
[width 512]))
which is not a syntax error but is a runtime error.
I do see an error message.
(regardless of the racket-error-context
value, so that idea of mine was n/a)
I guess I’ll need an example from you and/or some more information.
@jjsimpso
p.s. the error message I see is e.g. ; initialization for frame%: contract violation
; expected: label-string?
; given: 9999999999999
; Context (errortrace):
; /var/tmp/gui.rkt:3:14: (do-make-object lifted/1 frame% (list) (list (cons (quote ....) (....)) (cons (....) ....) (cons ....)))
displayed in the racket-repl-mode
buffer
Maybe you could M-x racket-bug-report
(that will includes some configuration settings you have) and a simple example?
@greg, it may take me some time to construct a minimal example. In general I do see contract errors from my GUI app in the repl buffer.
Ultimately I might need a minimal-ish example to be able to reproduce and fix. If that’s tough for you, meanwhile it might also be helpful to try the thing I suggested above with racket-error-context
. e.g. If it’s medium
, set it to high
(or vice versa) then try again and see if the error is displayed or not.
Those are somewhat different paths, including but not limited to using errortrace-lib
or not. Knowing which path is problemmatic might help me narrow it down and guess — maybe even be able to come up with the minimal example myself.
Or some other idea how to fix.
Another idea: If you can make the error display in the plain old REPL, then copy/pasting that exact error message text for me, might also give me a clue. (As one wild guess: If the error lacks any srcloc, e.g. no line:col info, that might be how/why it’s getting filtered — at least for one of the racket-error-context
value paths.)
(sorry, I know you’re just trying to write and debug your own program… not also mine :disappointed:)
@greg, ok I have a minimal example. And in drracket it does print the error messages. #lang racket/gui
(define download-list '("file1" "file2"))
(define download-panel%
(class horizontal-panel%
(inherit popup-menu)
(define/override (on-subwindow-event receiver evt)
(cond
[(send evt button-down?)
(eprintf "dl = ~a~n" download-list)
(let ([menu (new popup-menu%
[title "Download List"]
[popdown-callback
(lambda (pm ce) void)])])
(for ([dl (in-list download-list)])
(new menu-item%
[parent menu]
[label 999] ; if I change to [label 999] I don't see a contract error message
[callback (lambda (x y) (eprintf "cancelling ~a~n" dl))]))
(popup-menu menu 0 0))
#t]
[else
(super on-subwindow-event receiver evt)]))
(super-new)))
(define frame (new frame%
[label "test"]
[height 512]
[width 512]))
(define download-status
(new download-panel%
(parent frame)
(border 2)
(stretchable-width #f)
(stretchable-height #f)))
(define download-button
(new button%
(parent download-status)
(label "Downloads")
(stretchable-width #f)))
(send frame show #t)
Clicking the button will generate a contract violation.
In the simple example of just a frame like you tried above, I do see the contract error message in the racket-mode repl. So something about the more complex example is causing this.
This is the error I see in drracket: initialization for menu-item%: contract violation
expected: label-string?
given: 999
Thank you! I get same result. Now to figure out what’s going on…
Thank you! I haven’t tried setting the racket-error-context
since I can’t figure out how, i’m embarrassed to admit.
I did try ‘C-u F5’ to run my example and that didn’t change anything.
I created an issue for this: https://github.com/greghendershott/racket-mode/issues/543. I didn’t tag you there b/c I don’t know if you’re on GitHub and/or if you want to be tagged publicly.
I looked into a few “obvious” ideas but none panned out. I may need to tackle this tomorrow with a fresher brain.
Thanks for taking a look. I subscribed to the bug.