On this page:
impossible
format-application
format-values
format-exception

2.3 mischief/error: Reporting Errors

 (require mischief/error) package: mischief

Use in code that should be impossible to reach. Reports an error message including its source location. If applied as a function to arguments, those are included in the error message.

Examples:
> (define (sum xs)
    (match xs
      [(list x) x]
      [(cons x xs) (+ x (sum xs))]
      [_ impossible]))
> (sum (list 1 2 3 4))

10

> (sum (list))

impossible: internal error at eval:1.0; should never be

called

> (define (prod xs)
    (match xs
      [(list x) x]
      [(cons x xs) (* x (prod xs))]
      [_ (impossible xs)]))
> (prod (list 1 2 3 4))

24

> (prod (list))

impossible: internal error at eval:4.0; should never be

called: (impossible '())

procedure

(format-application proc    
  arg ...    
  #:<any-keyword> kw-arg ...)  string?
  proc : any/c
  arg : any/c
  kw-arg : any/c
Produces a string representing the application of proc to the supplied set of positional and keyword arguments.

Example:
> (format-application sort
    '(cat hat sat bat)
    string<?
    #:key symbol->string)

"(sort #:key #<procedure:symbol->string> '(cat hat sat bat) #<procedure:string<?>)"

procedure

(format-values arg ...)  string?

  arg : any/c
Produces a string representing an expression that returns the args as multiple values, or just the singular arg if only one is given.

Examples:
> (format-values 1 2 3)

"(values 1 2 3)"

> (format-values 1 2)

"(values 1 2)"

> (format-values 1)

"1"

> (format-values)

"(values)"

procedure

(format-exception x)  string?

  x : any/c
Produces a string representing an expression that raises x as an exception.

Examples:
> (format-exception
    (exn:fail:contract "Epic fail!"
    (current-continuation-marks)))

"(error \"Epic fail!\")"

> (format-exception 'not-an-exception)

"(raise 'not-an-exception)"