Skip to content
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

Fix pre-expr syntax #34

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

endvvell
Copy link

The code being fixed in this commit does not use proper syntax to specify :pre conditions. As a result, when any of the predicate functions are provided with the response parameter that is not a map, instead of throwing an assertion error, execution reaches (:status response) whereupon it produces NullPointerException.

This might cause confusion as to the origin of the error because the developer might not know or remember the proper syntax of the :pre conditions, and upon seeing that some code is present in the :pre header of the predicate functions they are using, they discard the possibility that it might be the response parameter they are providing to these functions that causes an error, assuming that the predicate functions take care of validating the proper type of the response parameter.

Judging from the way :pre condition gets added to the function definition, current implementation uses the syntax which doesn't fail to operate only because the assert function returns nil upon receiving a reference to a function and upon receiving the instance of the data type by itself, but the code does fail to fulfill its purpose, it doesn't really "work" as is.

;; part of code used to add pre to the body of the function:
(if pre
  (concat (map (fn* [c] `(assert ~c)) pre)
          body)
  body)

;; testing `map` function above with invalid and valid :pre conditions:

;; - invalid:
(map (fn* [c]
          (do
            (println "this is c" c)
            `(assert ~c))) '(map? "not-map"))

; this is c map?
; this is c not-map
((clojure.core/assert map?) ;; => nil
 (clojure.core/assert "not-map") ;; = nil
 )

;; - valid:
(map (fn* [c]
          (do
            (println "this is c" c)
            `(assert ~c))) '[(map? "not-map")])

; this is c (map? not-map)
((clojure.core/assert (map? "not-map")
  ;; \\> Execution error (AssertionError) ... Assert failed: (map? "not-map")
  ))

The code being fixed in this commit does not use proper syntax
to specify :pre conditions. As a result, when any of the predicate
functions are provided with the `response` parameter that is not a map,
instead of throwing an assertion error, execution reaches
`(:status response)` whereupon it produces `NullPointerException`.
@endvvell endvvell marked this pull request as ready for review August 14, 2024 14:49
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.

1 participant