 module.exports = (options) ->
 
   # if the certs are provided then try to read them now
-  readCerts options if options?
+  if options?
+    result = readCerts options
+    if result?.error? then return result
 
   new Cio options

class Cio

  constructor: (@_options) ->

    @_clientChain = buildChain()
    @_serverChain = buildChain()


    if @_options?.noRelisten then @_serverChain.disable 'cio/relistener'

    return


  client: (options) ->
    result = @_run @_clientChain, options
    if result?.failed? then result
    else result?.context?.client

  server: (options) ->
    result = @_run @_serverChain, options
    if result?.failed? then result
    else result?.context?.server

  _run: (chain, options) ->
    # # build options for chain.run(), choose the options which exists
