Comment by theteapot

Comment by theteapot 8 days ago

2 replies

> to a raciness in load_json where it's checked for file existence with an if and then carrying on as if the file is certainly there...

It's not a race. It's just redundant. If the file does not exist at the time you actually try to access it you get the same error with slightly better error message.

necovek 7 days ago

There is a log message that won't be output in that case: whether getting a full, "native" FileNotFound exception is better is beside the point, since the goal of the code was obviously to print a custom error message.

And it's trivial to achieve the desired effect sanely:

  try:
      with open(...) ...

  except FileNotFound:
      logger.error(...)
      raise
It'd even be fewer lines of code.
  • theteapot 6 days ago

    Or even fewer by doing it in a global exception handler instead of every time you try to open a file, since all your doing is piping the error though logger.