Clojure

Sequential destructuring of map gives confusing error message

Details

  • Type: Enhancement Enhancement
  • Status: Open Open
  • Priority: Minor Minor
  • Resolution: Unresolved
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Patch:
    Code and Test
  • Approval:
    Triaged

Description

The following broken code:

(let [[x y] {}] x)

provides the following stack trace:

Exception in thread "main" java.lang.UnsupportedOperationException: nth not supported on this type: PersistentArrayMap (test.clj:0)
        at clojure.lang.Compiler.eval(Compiler.java:4543)
        at clojure.lang.Compiler.load(Compiler.java:4857)
        at clojure.lang.Compiler.loadFile(Compiler.java:4824)
        at clojure.main$load_script__5833.invoke(main.clj:206)
        at clojure.main$script_opt__5864.invoke(main.clj:258)
        at clojure.main$main__5888.doInvoke(main.clj:333)
        at clojure.lang.RestFn.invoke(RestFn.java:413)
        at clojure.lang.Var.invoke(Var.java:346)
        at clojure.lang.AFn.applyToHelper(AFn.java:173)
        at clojure.lang.Var.applyTo(Var.java:463)
        at clojure.main.main(main.java:39)
Caused by: java.lang.UnsupportedOperationException: nth not supported on this type: PersistentArrayMap
        at clojure.lang.RT.nth(RT.java:800)
        at clojure.core$nth__3578.invoke(core.clj:873)
        at user$eval__1.invoke(test.clj:1)
        at clojure.lang.Compiler.eval(Compiler.java:4532)
        ... 10 more

The message "nth not supported on this type" while correct doesn't make the cause of the error very clear. Better error messages when destructuring would be very helpful.

  1. CLJ-5.patch
    11/Nov/11 7:38 PM
    2 kB
    Eugene Koontz
  2. clj-5-destructure-error.diff
    28/Apr/12 10:46 PM
    6 kB
    Carin Meier

Activity

Eugene Koontz made changes -
Field Original Value New Value
Attachment CLJ-5.patch [ 10697 ]
Carin Meier made changes -
Attachment better-error-for-let-vector-map-binding.patch [ 10725 ]
Aaron Bedra made changes -
Reporter Assembla Importer [ importer ]
Priority Minor [ 4 ]
Approval Incomplete [ 10006 ]
Patch Code and Test [ 10002 ]
Carin Meier made changes -
Attachment clj-5-part1.patch [ 10747 ]
Attachment clj-5-part2.patch [ 10748 ]
Carin Meier made changes -
Attachment clj-5-part2.patch [ 10748 ]
Carin Meier made changes -
Attachment clj-5-part1.patch [ 10747 ]
Carin Meier made changes -
Attachment better-error-for-let-vector-map-binding.patch [ 10725 ]
Carin Meier made changes -
Comment [ Based on feedback, expanded checker to look for nth errors.
Uses patches: clj-5-part1.patch and clj5-part2.patch

Will produce
{code}
user=> (let [[x y] {}] x)
Exception let cannot destructure class clojure.lang.PersistentArrayMap. Try converting it to a seq. clojure.core/check-nth-errors (core.clj:3909)
user=> (let [[x y] #{}] x)
Exception let cannot destructure class clojure.lang.PersistentHashSet. Try converting it to a seq. clojure.core/check-nth-errors (core.clj:3909)
user=> (let [[x y] 1] x)
Exception let cannot destructure class java.lang.Long. clojure.core/check-nth-errors (core.clj:3910)
{code} ]
Carin Meier made changes -
Attachment clj-5-destructure-error.diff [ 11124 ]
Alex Miller made changes -
Approval Incomplete [ 10006 ] Vetted [ 10003 ]
Alex Miller made changes -
Labels errormsgs
Alex Miller made changes -
Summary Unintuitive error response in clojure 1.0 Sequential destructuring of map gives confusing error message
Fix Version/s Backlog [ 10035 ]
Description The following broken code:

(let [[x y] {}] x)

provides the following stack trace:

Exception in thread "main" java.lang.UnsupportedOperationException: nth not supported on this type: PersistentArrayMap (test.clj:0)
        at clojure.lang.Compiler.eval(Compiler.java:4543)
        at clojure.lang.Compiler.load(Compiler.java:4857)
        at clojure.lang.Compiler.loadFile(Compiler.java:4824)
        at clojure.main$load_script__5833.invoke(main.clj:206)
        at clojure.main$script_opt__5864.invoke(main.clj:258)
        at clojure.main$main__5888.doInvoke(main.clj:333)
        at clojure.lang.RestFn.invoke(RestFn.java:413)
        at clojure.lang.Var.invoke(Var.java:346)
        at clojure.lang.AFn.applyToHelper(AFn.java:173)
        at clojure.lang.Var.applyTo(Var.java:463)
        at clojure.main.main(main.java:39)
Caused by: java.lang.UnsupportedOperationException: nth not supported on this type: PersistentArrayMap
        at clojure.lang.RT.nth(RT.java:800)
        at clojure.core$nth__3578.invoke(core.clj:873)
        at user$eval__1.invoke(test.clj:1)
        at clojure.lang.Compiler.eval(Compiler.java:4532)
        ... 10 more

The message "nth not supported on this type" while correct doesn't make the cause of the error very clear. Better error messages when destructuring would be very helpful.
The following broken code:

{code}
(let [[x y] {}] x)
{code}

provides the following stack trace:

{code}
Exception in thread "main" java.lang.UnsupportedOperationException: nth not supported on this type: PersistentArrayMap (test.clj:0)
        at clojure.lang.Compiler.eval(Compiler.java:4543)
        at clojure.lang.Compiler.load(Compiler.java:4857)
        at clojure.lang.Compiler.loadFile(Compiler.java:4824)
        at clojure.main$load_script__5833.invoke(main.clj:206)
        at clojure.main$script_opt__5864.invoke(main.clj:258)
        at clojure.main$main__5888.doInvoke(main.clj:333)
        at clojure.lang.RestFn.invoke(RestFn.java:413)
        at clojure.lang.Var.invoke(Var.java:346)
        at clojure.lang.AFn.applyToHelper(AFn.java:173)
        at clojure.lang.Var.applyTo(Var.java:463)
        at clojure.main.main(main.java:39)
Caused by: java.lang.UnsupportedOperationException: nth not supported on this type: PersistentArrayMap
        at clojure.lang.RT.nth(RT.java:800)
        at clojure.core$nth__3578.invoke(core.clj:873)
        at user$eval__1.invoke(test.clj:1)
        at clojure.lang.Compiler.eval(Compiler.java:4532)
        ... 10 more
{code}

The message "nth not supported on this type" while correct doesn't make the cause of the error very clear. Better error messages when destructuring would be very helpful.
Alex Miller made changes -
Approval Vetted [ 10003 ] Triaged [ 10120 ]
Alex Miller made changes -
Labels errormsgs destructuring errormsgs

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated: