 	key: 'unknown'
 	template: BaseError.template
 		
-	toJSON: ->
-		key: @key
-		message: @message
+	toJSON: -> [@key, @message]
 		
 exports.errorTypes = ->
 	

	pkgman.invoke 'errorType', (path, spec) -> collected.push spec
		
	types = {}
	types[(new Type).key] = Type for Type in collected
	types

exports.serialize = (error) ->

	output = output.replace ":#{key}", value for key, value of error
	output
	
exports.instantiate = (key, args...) ->
	
	Types = exports.errorTypes()
	Type = if Types[key]? then Types[key] else BaseError
	
	Type = do (Type) ->
		
		F = (args) -> Type.apply this, args
		F.prototype = Type.prototype
		
		(args) -> new F args
	
	Type args
	
exports.caught = (error) ->
	return error unless error instanceof BaseError
