diff --git a/jupyter_conda/envmanager.py b/jupyter_conda/envmanager.py index afa5a62d..a4b062b2 100644 --- a/jupyter_conda/envmanager.py +++ b/jupyter_conda/envmanager.py @@ -340,7 +340,9 @@ def get_info(env): return {"environments": envs_list} - async def update_env(self, env: str, file_content: str, file_name: str = "environment.yml") -> Dict[str, str]: + async def update_env( + self, env: str, file_content: str, file_name: str = "environment.yml" + ) -> Dict[str, str]: """Update a environment from a file. Args: @@ -512,8 +514,9 @@ async def list_available(self) -> Dict[str, List[Dict[str, str]]]: try: # Skip if file is not accessible with open(path) as f: channeldata = json.load(f) - except OSError as err: - self.log.info("[jupyter_conda] Error: {}".format(str(err))) + except (json.JSONDecodeError, OSError, ValueError) as err: + self.log.info("[jupyter_conda] {!s} skipped".format(path)) + self.log.debug(str(err)) else: pkg_info.update(channeldata["packages"]) else: @@ -527,13 +530,20 @@ async def list_available(self) -> Dict[str, List[Dict[str, str]]]: ) except Exception as e: self.log.info( - "[jupyter_conda] Error getting {}/channeldata.json: {}".format( - channel, str(e) - ) + "[jupyter_conda] {}/channeldata.json skipped.".format(channel) ) + self.log.debug(str(e)) else: channeldata = response.body.decode("utf-8") - pkg_info.update(json.loads(channeldata)["packages"]) + try: + pkg_info.update(json.loads(channeldata)["packages"]) + except (json.JSONDecodeError, ValueError) as error: + self.log.info( + "[jupyter_conda] {}/channeldata.json skipped.".format( + channel + ) + ) + self.log.debug(str(error)) # Example structure channeldata['packages'] for channeldata_version == 1 # "tmpc0d7d950": { diff --git a/jupyter_conda/handlers.py b/jupyter_conda/handlers.py index 75fb3599..47e52614 100644 --- a/jupyter_conda/handlers.py +++ b/jupyter_conda/handlers.py @@ -177,7 +177,7 @@ async def get(self): self.finish(tornado.escape.json_encode(list_envs)) @tornado.web.authenticated - async def post(self): + def post(self): """`POST /environments` creates an environment. Method of creation depends on the request data (first find is used): @@ -220,7 +220,7 @@ class EnvironmentHandler(EnvBaseHandler): """Environment handler.""" @tornado.web.authenticated - async def delete(self, env: str): + def delete(self, env: str): """`DELETE /environments/` deletes an environment.""" idx = self._stack.put(self.env_manager.delete_env, env) @@ -263,7 +263,6 @@ async def get(self, env: str): self.finish(tornado.escape.json_encode(packages)) @tornado.web.authenticated - @tornado.gen.coroutine def patch(self, env: str): """`PATCH /environments/` update an environment. @@ -286,7 +285,7 @@ class PackagesEnvironmentHandler(EnvBaseHandler): """Handle actions on environment packages.""" @tornado.web.authenticated - async def delete(self, env: str): + def delete(self, env: str): """`DELETE /environments//packages` delete some packages. Request json body: @@ -300,7 +299,7 @@ async def delete(self, env: str): self.redirect_to_task(idx) @tornado.web.authenticated - async def patch(self, env: str): + def patch(self, env: str): """`PATCH /environments//packages` update some packages. If no packages are provided, update all possible packages. @@ -316,7 +315,7 @@ async def patch(self, env: str): self.redirect_to_task(idx) @tornado.web.authenticated - async def post(self, env: str): + def post(self, env: str): """`POST /environments//packages` install some packages. Packages can be installed in development mode. In that case, @@ -366,11 +365,8 @@ async def get(self): with open(cache_file) as cache: cache_data = cache.read() except OSError as e: - logger.info( - "[jupyter_conda] No available packages list in cache {!s}.".format( - e - ) - ) + logger.info("[jupyter_conda] No available packages list in cache.") + logger.debug(str(e)) async def update_available( env_manager: EnvManager, cache_file: str, return_packages: bool = True @@ -380,11 +376,8 @@ async def update_available( with open(cache_file, "w+") as cache: json.dump(answer, cache) except (ValueError, OSError) as e: - logger.info( - "[jupyter_conda] Fail to cache available packages {!s}.".format( - e - ) - ) + logger.info("[jupyter_conda] Fail to cache available packages.") + logger.debug(str(e)) else: # Change rights to ensure every body can update the cache os.chmod(