
import os
import json

class JSONConfigLoader():
    def __init__(self):
        self.sources = [
            os.path.dirname(os.getcwd()),
            os.path.dirname(os.path.abspath(__file__)),
            os.path.expanduser('~'),
            '/etc',
        ]

    def load(self, filename):
        for source in self.sources:
            file_path = os.path.join(source, filename)
            if not os.path.exists(file_path):
                continue
            with open(file_path) as f:
                return json.load(f)

        return None


import os
import json

class JSONConfigLoader():
    def __init__(self, base_path):
        self.sources = [
            os.path.dirname(os.getcwd()),
            os.path.dirname(os.path.abspath(base_path)),
            os.path.expanduser('~'),
            '/etc',
        ]

    def load(self, filename):
        tries = []
        for source in self.sources:
            file_path = os.path.join(source, filename)
            tries.append(file_path)
            if not os.path.exists(file_path):
                continue
            with open(file_path) as f:
                return json.load(f)

        raise Exception("Config file not found in: %s" % tries)

Raise exception in case of config load error
Raise exception in case of config load error

  
  import os
  import json
  
  class JSONConfigLoader():
-     def __init__(self):
+     def __init__(self, base_path):
          self.sources = [
              os.path.dirname(os.getcwd()),
-             os.path.dirname(os.path.abspath(__file__)),
+             os.path.dirname(os.path.abspath(base_path)),
              os.path.expanduser('~'),
              '/etc',
          ]
  
      def load(self, filename):
+         tries = []
          for source in self.sources:
              file_path = os.path.join(source, filename)
+             tries.append(file_path)
              if not os.path.exists(file_path):
                  continue
              with open(file_path) as f:
                  return json.load(f)
  
-         return None
+         raise Exception("Config file not found in: %s" % tries)
  
Raise exception in case of config load error
## Code Before:

import os
import json

class JSONConfigLoader():
    def __init__(self):
        self.sources = [
            os.path.dirname(os.getcwd()),
            os.path.dirname(os.path.abspath(__file__)),
            os.path.expanduser('~'),
            '/etc',
        ]

    def load(self, filename):
        for source in self.sources:
            file_path = os.path.join(source, filename)
            if not os.path.exists(file_path):
                continue
            with open(file_path) as f:
                return json.load(f)

        return None

## Instruction:
Raise exception in case of config load error
## Code After:

import os
import json

class JSONConfigLoader():
    def __init__(self, base_path):
        self.sources = [
            os.path.dirname(os.getcwd()),
            os.path.dirname(os.path.abspath(base_path)),
            os.path.expanduser('~'),
            '/etc',
        ]

    def load(self, filename):
        tries = []
        for source in self.sources:
            file_path = os.path.join(source, filename)
            tries.append(file_path)
            if not os.path.exists(file_path):
                continue
            with open(file_path) as f:
                return json.load(f)

        raise Exception("Config file not found in: %s" % tries)
