• Stars
    star
    271
  • Rank 151,717 (Top 3 %)
  • Language
    Clojure
  • License
    MIT License
  • Created over 15 years ago
  • Updated almost 10 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

More readable stacktraces for Clojure

clj-stacktrace

A library for creating more readable stacktraces in Clojure programs.

For example, to print a nice stack trace in a REPL:

=> (use 'clj-stacktrace.repl)
=> ("foo")
java.lang.ClassCastException: java.lang.String cannot be cast to clojure.lang.IFn (NO_SOURCE_FILE:0)
       Compiler.java:5440 clojure.lang.Compiler.eval
       Compiler.java:5391 clojure.lang.Compiler.eval
            core.clj:2382 clojure.core/eval
             main.clj:183 clojure.main/repl[fn]
             main.clj:204 clojure.main/repl[fn]
             main.clj:204 clojure.main/repl
          RestFn.java:422 clojure.lang.RestFn.invoke
             main.clj:262 clojure.main/repl-opt
             main.clj:355 clojure.main/main
          RestFn.java:398 clojure.lang.RestFn.invoke
             Var.java:361 clojure.lang.Var.invoke
             AFn.java:159 clojure.lang.AFn.applyToHelper
             Var.java:482 clojure.lang.Var.applyTo
             main.java:37 clojure.main.main
Caused by: java.lang.String cannot be cast to clojure.lang.IFn
         NO_SOURCE_FILE:2 user/eval100
       Compiler.java:5424 clojure.lang.Compiler.eval

In stack traces printed by pst:

  • Java methods are described with the usual name.space.ClassName.methodName convention and Clojure functions with their own name.space/function-name convention.
  • Anonymous clojure functions are denoted by adding an [fn] to their enclosing, named function.
  • "Caused by" cascades are shown as in regular java stack traces.
  • Elements are vertically aligned for better readability.
  • Printing is directed to *out*.

If you want to direct the printing to somewhere other than *out*, either use pst-on to specify the output location or pst-str to capture the printing as a string.

The library also offers an API for programatically 'parsing' exceptions. This API is used internal for pst and can be used to e.g. improve development tools. Try for example:

(use 'clj-stacktrace.core)
(try
  ("nofn")
  (catch Exception e
    (parse-exception e)))

Leiningen

If you use Leiningen, you can install clj-stacktrace on a user-wide basis. Just add the following to ~/.lein/profiles.clj:

{:user {:dependencies [[clj-stacktrace "0.2.8"]]
        :injections [(let [orig (ns-resolve (doto 'clojure.stacktrace require)
                                            'print-cause-trace)
                           new (ns-resolve (doto 'clj-stacktrace.repl require)
                                           'pst)]
                       (alter-var-root orig (constantly (deref new))))]}}

The :injections clause replaces the built-in stack trace printing with enhanced clj-stacktrace version; you can leave it out if you plan on invoking clj-stacktrace functions directly or are using tools which are already clj-stacktrace-aware.

License

Copyright © 2009-2013 Mark McGranaghan and contributors.

Released under an MIT license.

More Repositories

1

gobyexample

Go by Example
Go
7,224
star
2

services-engineering

A reading list for services engineering, with a focus on cloud infrastructure services
3,612
star
3

fleetdb

A schema-free database implemented in Clojure
Clojure
170
star
4

clj-json

Fast JSON encoding and decoding for Clojure via the Jackson library
Clojure
90
star
5

clj-redis

Clojure Redis client library
Clojure
79
star
6

pgpin

Example of a database-backed service in Go
Go
62
star
7

zk

Zookeeper CLI designed to be fast, easy to install, and Unix-friendly
Go
59
star
8

clj-garden

Where I grow Clojure codes
Clojure
56
star
9

clj-html

Fast HTML templates in Clojure
Clojure
45
star
10

textmate-clojure

TextMate bundle providing syntax highlighting for Clojure
30
star
11

gitcred

PageRank applied to the GitHub users/follows graph
Clojure
29
star
12

ring-json-params

Ring middleware for parsing JSON into params
Clojure
29
star
13

adder

Sample Clojure web application.
Clojure
25
star
14

weld

A Clojure web framework built on Ring: expressive and fast in a functional style
Clojure
23
star
15

gorg

Persistence for Doozer
Ruby
22
star
16

cabinet

Sample Clojure web application with REST API
Clojure
22
star
17

clj-doc

HTML documentation for Clojure libraries.
JavaScript
21
star
18

petrify

High-durability persistence for log-structured datastores
Ruby
18
star
19

zookeeper-and-go

Example code and Vagrant configurations for getting started with Zookeeper and Go
Go
17
star
20

clj-riak

Clojure bindings to the Riak Protocol Buffers API.
Clojure
16
star
21

fleetdb-client

Clojure client for FleetDB
Clojure
15
star
22

golit

literate-programming-style documentation for Go source
Go
14
star
23

hammockdb

Clojure+Ring CouchDB API implementation
Clojure
13
star
24

clj-serializer

Fast binary serialization and deserialization for Clojure data structures
Java
10
star
25

cljs-demo

Sample programs demonstrating ClojureScript targeted at Node.js
Clojure
10
star
26

clj-unit

Clojure unit testing library: non-magical and developer friendly
Clojure
9
star
27

pg2librato

Periodically query a Postgres DB and emit resuling metrics to Librato
Go
9
star
28

clj-routing

Fast, 2-way, generic URL routing library for use by Clojure web frameworks
Clojure
8
star
29

db-compare

Benchmarking open-source databases
Clojure
6
star
30

spine

Beanstalkd-backed job queueing for Clojure
Clojure
6
star
31

ring-httpcore-adapter

Ring adapter for the Apache HttpCore webserver
Clojure
5
star
32

clj-html-helpers

Helpers for the clj-html Clojure HTML library.
Clojure
5
star
33

fleet-rb

Ruby client for FleetDB
Ruby
4
star
34

heroku-redisgreen

Heroku client plugin for RedisGreen
Ruby
3
star
35

twine

Beanstalkd Clojure client
Clojure
1
star
36

thompson

JVM library for computational algebra in Thompson's group F
Java
1
star
37

tidytrello

Find stale boards in your Trello org
Go
1
star
38

doozer-ops

Ops evaluation notes for Doozer
Shell
1
star