]> gitweb.factorcode.org Git - factor.git/commitdiff
json.writer: add an explicit error when serializing fp-specials
authorJon Harper <jon.harper87@gmail.com>
Fri, 2 Jan 2015 18:39:14 +0000 (19:39 +0100)
committerDoug Coleman <doug.coleman@gmail.com>
Thu, 11 Jun 2015 05:51:39 +0000 (22:51 -0700)
basis/json/json.factor
basis/json/writer/writer-docs.factor
basis/json/writer/writer.factor

index b68290ba28f8e851669a0a9cd1422e46384c5d9d..b60652bcb07fa2d7c8afe30bab032ca08abe0569 100644 (file)
@@ -1,10 +1,13 @@
-USING: kernel vocabs ;
+USING: kernel vocabs summary debugger io ;
 IN: json
 
 SINGLETON: json-null
 
 ERROR: json-error ;
 
+ERROR: json-fp-special-error value ;
+M: json-fp-special-error summary drop "JSON serialization: illegal float:" ;
+
 : if-json-null ( x if-null else -- )
     [ dup json-null? ]
     [ [ drop ] prepose ]
index e027e4d1c83793945e8e102ce0fb4b359d8e419e..6d441cfc57a86bc3f1e71364c09a5ba133f58fe0 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (C) 2006 Chris Double.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: help.markup help.syntax kernel ;
+USING: json help.markup help.syntax kernel ;
 IN: json.writer
 
 HELP: >json
@@ -23,6 +23,11 @@ $nl
 }
 { $see-also >json } ;
 
+{ json-fp-special-error json-allow-fp-special? } related-words
+
+HELP: json-fp-special-error
+{ $error-description "Thrown by " { $link "json.writer" } " when attempting to serialize -1/0. or +1/0. or NaN when " { $link json-allow-fp-special? } " is not enabled." } ;
+
 ARTICLE: "json.writer" "JSON writer"
 "The " { $vocab-link "json.writer" } " vocabulary defines words for converting objects to JSON format."
 { $subsections
index f7bc35ec6eadf1f66be1d0b6618935b822a0be23..9795b993e18de433da475498372fd46e027e698d 100644 (file)
@@ -94,7 +94,7 @@ M: integer stream-json-print
 
 : float>json ( float -- string )
     dup fp-special? [
-        json-allow-fp-special? get [ json-error ] unless
+        json-allow-fp-special? get [ json-fp-special-error ] unless
         {
             { [ dup fp-nan? ] [ drop "NaN" ] }
             { [ dup 1/0. = ] [ drop "Infinity" ] }