Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 897

Show
Ignore:
Timestamp:
12/29/05 18:03:29
Author:
fumanchu
Message:

Fix for #413 (Improve configuration error behavior).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cherrypy/_cperror.py

    r865 r897  
    1111 
    1212class WrongConfigValue(Error): 
    13     """ Happens when unrepr can't parse a config value """ 
     13    """ Happens when a config value can't be parsed, or is otherwise illegal. """ 
    1414    pass 
    1515 
  • trunk/cherrypy/_cpserver.py

    r889 r897  
    6464        self.blocking = not initOnly 
    6565        self.httpserverclass = serverClass 
     66         
     67        # Hmmm...we *could* check config in _start instead, but I think 
     68        # most people would like CP to fail before autoreload kicks in. 
     69        check_config() 
    6670         
    6771        # Autoreload, but check serverClass. If None, we're not starting 
     
    269273 
    270274 
     275def check_config(): 
     276    err = cherrypy.WrongConfigValue 
     277    for name, section in cherrypy.config.configs.iteritems(): 
     278        for k, v in section.iteritems(): 
     279            if k == "server.environment": 
     280                if v and v not in cherrypy.config.environments: 
     281                    raise err("'%s' is not a registered environment." % v) 
     282 
     283 
    271284def configure(): 
    272285    """Perform one-time actions to prepare the CherryPy core.""" 
  • trunk/cherrypy/test/test_states.py

    r856 r897  
    163163            self.assertEqual(db_connection.running, False) 
    164164            self.assertEqual(len(db_connection.threads), 0) 
     165     
     166    def test_3_ConfigErrors(self): 
     167        cherrypy.config.update({'server.environment': 'destruction'}) 
     168        try: 
     169            self.assertRaises(cherrypy.WrongConfigValue, 
     170                              cherrypy.server.start, True, self.serverClass) 
     171        finally: 
     172            cherrypy.server.stop() 
    165173 
    166174 

Hosted by WebFaction

Log in as guest/cpguest to create tickets