Repository: conda/conda

Issue:
MemoryError
```
error: MemoryError()
command: C:\Users\Jason\Anaconda3\Scripts\conda install rise
user_agent: conda/4.4.7 requests/2.18.4 CPython/3.6.3 Windows/10 Windows/10.0.16299
_messageid: -9223372036837525402
_messagetime: 1515517517366 / 2018-01-09 11:05:17

MemoryError

During handling of the above exception, another exception occurred:

MemoryError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Jason\Anaconda3\lib\site-packages\conda\exceptions.py", line 743, in __call__
    return func(*args, **kwargs)
  File "C:\Users\Jason\Anaconda3\lib\site-packages\conda\cli\main.py", line 78, in _main
    exit_code = do_call(args, p)
  File "C:\Users\Jason\Anaconda3\lib\site-packages\conda\cli\conda_argparse.py", line 76, in do_call
    exit_code = getattr(module, func_name)(args, parser)
  File "C:\Users\Jason\Anaconda3\lib\site-packages\conda\cli\main_install.py", line 11, in execute
    install(args, parser, 'install')
  File "C:\Users\Jason\Anaconda3\lib\site-packages\conda\cli\install.py", line 236, in install
    force_reinstall=context.force,
  File "C:\Users\Jason\Anaconda3\lib\site-packages\conda\core\solve.py", line 504, in solve_for_transaction
    force_remove, force_reinstall)
  File "C:\Users\Jason\Anaconda3\lib\site-packages\conda\core\solve.py", line 437, in solve_for_diff
    final_precs = self.solve_final_state(deps_modifier, prune, ignore_pinned, force_remove)
  File "C:\Users\Jason\Anaconda3\lib\site-packages\conda\core\solve.py", line 145, in solve_final_state
    solution = tuple(Dist(d) for d in prefix_data.iter_records())
  File "C:\Users\Jason\Anaconda3\lib\site-packages\conda\core\linked_data.py", line 90, in iter_records
    return itervalues(self._prefix_records)
  File "C:\Users\Jason\Anaconda3\lib\site-packages\conda\core\linked_data.py", line 110, in _prefix_records
    return self.__prefix_records or self.load() or self.__prefix_records
  File "C:\Users\Jason\Anaconda3\lib\site-packages\conda\core\linked_data.py", line 48, in load
    self._load_single_record(meta_file)
  File "C:\Users\Jason\Anaconda3\lib\site-packages\conda\core\linked_data.py", line 116, in _load_single_record
    prefix_record = PrefixRecord(**json_data)
  File "C:\Users\Jason\Anaconda3\lib\site-packages\conda\_vendor\auxlib\entity.py", line 718, in __call__
    instance = super(EntityType, cls).__call__(*args, **kwargs)
  File "C:\Users\Jason\Anaconda3\lib\site-packages\conda\_vendor\auxlib\entity.py", line 735, in __init__
    setattr(self, key, kwargs[key])
  File "C:\Users\Jason\Anaconda3\lib\site-packages\conda\_vendor\auxlib\entity.py", line 427, in __set__
    instance.__dict__[self.name] = self.validate(instance, self.box(instance, instance.__class__, val))
  File "C:\Users\Jason\Anaconda3\lib\site-packages\conda\_vendor\auxlib\entity.py", line 666, in box
    return self._type(**val)
  File "C:\Users\Jason\Anaconda3\lib\site-packages\conda\_vendor\auxlib\entity.py", line 718, in __call__
    instance = super(EntityType, cls).__call__(*args, **kwargs)
  File "C:\Users\Jason\Anaconda3\lib\site-packages\conda\_vendor\auxlib\entity.py", line 735, in __init__
    setattr(self, key, kwargs[key])
  File "C:\Users\Jason\Anaconda3\lib\site-packages\conda\_vendor\auxlib\entity.py", line 427, in __set__
    instance.__dict__[self.name] = self.validate(instance, self.box(instance, instance.__class__, val))
  File "C:\Users\Jason\Anaconda3\lib\site-packages\conda\_vendor\auxlib\entity.py", line 590, in box
    return self._type(v if isinstance(v, et) else et(**v) for v in val)
  File "C:\Users\Jason\Anaconda3\lib\site-packages\conda\_vendor\auxlib\entity.py", line 590, in <genexpr>
    return self._type(v if isinstance(v, et) else et(**v) for v in val)
  File "C:\Users\Jason\Anaconda3\lib\site-packages\conda\_vendor\auxlib\entity.py", line 718, in __call__
    instance = super(EntityType, cls).__call__(*args, **kwargs)
MemoryError

```


Discussion:

Resolving patch:
diff --git a/conda/exceptions.py b/conda/exceptions.py
--- a/conda/exceptions.py
+++ b/conda/exceptions.py
@@ -592,6 +592,12 @@ def __init__(self, message):
         super(SafetyError, self).__init__(message)
 
 
+class CondaMemoryError(MemoryError, CondaError):
+    def __init__(self, caused_by, **kwargs):
+        message = "The conda process ran out of memory. Increase system memory and/or try again."
+        super(CondaMemoryError, self).__init__(message, caused_by=caused_by, **kwargs)
+
+
 class NotWritableError(CondaError, OSError):
 
     def __init__(self, path, errno, **kwargs):
@@ -784,6 +790,8 @@ def handle_exception(self, exc_val, exc_tb):
         if isinstance(exc_val, EnvironmentError):
             if getattr(exc_val, 'errno', None) == ENOSPC:
                 return self.handle_application_exception(NoSpaceLeftError(exc_val), exc_tb)
+        if isinstance(exc_val, MemoryError):
+            return self.handle_application_exception(CondaMemoryError(exc_val), exc_tb)
         if isinstance(exc_val, KeyboardInterrupt):
             self._print_conda_exception(CondaError("KeyboardInterrupt"), _format_exc())
             return 1


Test patch: