PageRenderTime 58ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/pkgs/unstable-pkgs/unstable-doc/scribblings/error.scrbl

http://github.com/plt/racket
Unknown | 112 lines | 90 code | 22 blank | 0 comment | 0 complexity | 15e520a292708b0f9f533d958f531468 MD5 | raw file
Possible License(s): LGPL-3.0, GPL-3.0, BSD-3-Clause, CC-BY-SA-3.0
  1. #lang scribble/manual
  2. @(require scribble/eval "utils.rkt"
  3. (for-label racket/base racket/contract unstable/error))
  4. @(define the-eval (make-base-eval))
  5. @(the-eval '(require unstable/error))
  6. @title[#:tag "error"]{Errors}
  7. @unstable[@author+email["Ryan Culpepper" "ryanc@racket-lang.org"]]
  8. @defmodule[unstable/error]
  9. @defproc[(error* [name symbol?]
  10. [message string?]
  11. [field (let ([option/c (or/c 'value 'multi 'maybe)])
  12. (or/c string? (cons/c string? (listof option/c))))]
  13. [value any/c] ... ...
  14. [#:continued continued-message (or/c string? (listof string?)) null])
  15. any]{
  16. Raises an exception with a message composed according to the Racket
  17. @tech[#:doc '(lib "scribblings/reference/reference.scrbl")]{error
  18. message convention}. The raised exception is an instance of
  19. @racket[exn:fail].
  20. The composed error message includes details consisting of the
  21. alternating @racket[field] and @racket[value] arguments. By default,
  22. @racket[value] is formatted as if by @racket[display] unless it is
  23. @racket[#f], in which case the detail line is omitted. The following
  24. options affect the formatting of the detail line:
  25. @itemlist[
  26. @item{@racket['multi] formats each element in the corresponding @racket[value],
  27. which must be a list, as a separate line; if @racket['maybe] is also provided,
  28. then the detail line is omitted if the list is empty}
  29. @item{@racket['value] formats the value using
  30. @racket[error-value->string-handler]; the detail line is not omittable
  31. unless @racket['maybe] or @racket['multi] is also provided}
  32. ]
  33. @examples[#:eval the-eval
  34. (error* 'mcbean "too many stars upon thars"
  35. '("given" value) 'star-bellied-sneetch
  36. '("stars" value) 3)
  37. (error* 'hal "unable to open pod bay doors"
  38. #:continued "this mission is too important to let you jeopardize it"
  39. "threat" "David Bowman"
  40. "detection" "lip reading")
  41. (error* 'car "missing car keys"
  42. '("searched" multi)
  43. (list "dresser" "desk" "kitchen table" "under sofa"
  44. "behind microwave" "in washing machine")
  45. "last seen"
  46. #f)
  47. ]
  48. }
  49. @defproc[(raise-syntax-error*
  50. [message string?]
  51. [expr (or/c syntax? #f)]
  52. [sub-expr (or/c syntax? #f)]
  53. [field (let ([option/c (or/c 'value 'multi 'maybe)])
  54. (or/c string? (cons/c string? (listof option/c))))]
  55. [value any/c] ... ...
  56. [#:continued continued-message (or/c string? (listof string?)) null])
  57. any]{
  58. Like @racket[raise-syntax-error] but with the formatting of
  59. @racket[error*]. The raised exception is an instance of
  60. @racket[exn:fail:syntax]. Like @racket[raise-syntax-error], the
  61. inclusion of @racket[expr] and @racket[sub-expr] in the details of the
  62. error message is controlled by the
  63. @racket[error-print-source-location] paramter; if they included, they
  64. are included before the other details specified by @racket[field] and
  65. @racket[value]. Unlike @racket[raise-syntax-error], both @racket[expr]
  66. and @racket[sub-expr] are mandatory arguments.
  67. }
  68. @defproc[(compose-error-message
  69. [name (or/c symbol? #f)]
  70. [message string?]
  71. [field (let ([option/c (or/c 'value 'multi 'maybe)])
  72. (or/c string? (cons/c string? (listof option/c))))]
  73. [value any/c] ... ...
  74. [#:continued continued-message (or/c string? (listof string?)) null])
  75. string?]{
  76. Like @racket[error*], but produces a string conforming to
  77. the Racket @tech[#:doc '(lib
  78. "scribblings/reference/reference.scrbl")]{error message convention}.
  79. }
  80. @defproc[(compose-error-detail
  81. [field string?]
  82. [options (listof (or/c 'value 'multi 'maybe))]
  83. [value any/c])
  84. string?]{
  85. Formats a single detail for an error message. The @racket[options]
  86. behave as described in @racket[error*].
  87. The resulting string begins with a newline unless it is empty, so it
  88. can be appended to the end of a base error message.
  89. }
  90. @(close-eval the-eval)