Repository: conan-io/conan

Issue:
Cryptic error message for invalid CONAN_CPU_COUNT values
- [x] I've read the [CONTRIBUTING guide](https://github.com/conan-io/conan/blob/develop/.github/CONTRIBUTING.md).
- [x] I've specified the Conan version, operating system version and any tool that can be relevant.
- [x] I've explained the steps to reproduce the error or the motivation/use case of the question/suggestion.

```
> conan --version
Conan version 1.11.2
```

Currently, when `CONAN_CPU_COUNT` env variable is set to an invalid non-integer value, a call to `conan build` for `CMake` based packages results in quite cryptic error message, e.g. here is an example for `CONAN_CPU_COUNT=null`:
```
ERROR: <snip>: Error in build() method, line 84
        cmake = CMake(self)
        ValueError: invalid literal for int() with base 10: 'null'
```
It may take some time to grasp what's the reason especially on large code bases or when environment is set by some intermediary like Jenkins' pipeline or so.
It would be nice to have a proper validation and more user friendly error message to cut down investigation time to a minimum.
Cryptic error message for invalid CONAN_CPU_COUNT values
- [x] I've read the [CONTRIBUTING guide](https://github.com/conan-io/conan/blob/develop/.github/CONTRIBUTING.md).
- [x] I've specified the Conan version, operating system version and any tool that can be relevant.
- [x] I've explained the steps to reproduce the error or the motivation/use case of the question/suggestion.

```
> conan --version
Conan version 1.11.2
```

Currently, when `CONAN_CPU_COUNT` env variable is set to an invalid non-integer value, a call to `conan build` for `CMake` based packages results in quite cryptic error message, e.g. here is an example for `CONAN_CPU_COUNT=null`:
```
ERROR: <snip>: Error in build() method, line 84
        cmake = CMake(self)
        ValueError: invalid literal for int() with base 10: 'null'
```
It may take some time to grasp what's the reason especially on large code bases or when environment is set by some intermediary like Jenkins' pipeline or so.
It would be nice to have a proper validation and more user friendly error message to cut down investigation time to a minimum.
Cryptic error message for invalid CONAN_CPU_COUNT values
- [x] I've read the [CONTRIBUTING guide](https://github.com/conan-io/conan/blob/develop/.github/CONTRIBUTING.md).
- [x] I've specified the Conan version, operating system version and any tool that can be relevant.
- [x] I've explained the steps to reproduce the error or the motivation/use case of the question/suggestion.

```
> conan --version
Conan version 1.11.2
```

Currently, when `CONAN_CPU_COUNT` env variable is set to an invalid non-integer value, a call to `conan build` for `CMake` based packages results in quite cryptic error message, e.g. here is an example for `CONAN_CPU_COUNT=null`:
```
ERROR: <snip>: Error in build() method, line 84
        cmake = CMake(self)
        ValueError: invalid literal for int() with base 10: 'null'
```
It may take some time to grasp what's the reason especially on large code bases or when environment is set by some intermediary like Jenkins' pipeline or so.
It would be nice to have a proper validation and more user friendly error message to cut down investigation time to a minimum.


Discussion:

Resolving patch:
diff --git a/conans/client/tools/oss.py b/conans/client/tools/oss.py
--- a/conans/client/tools/oss.py
+++ b/conans/client/tools/oss.py
@@ -24,6 +24,9 @@ def cpu_count(output=None):
     output = default_output(output, 'conans.client.tools.oss.cpu_count')
     try:
         env_cpu_count = os.getenv("CONAN_CPU_COUNT", None)
+        if env_cpu_count is not None and not env_cpu_count.isdigit():
+            raise ConanException("Invalid CONAN_CPU_COUNT value '%s', "
+                                 "please specify a positive integer" % env_cpu_count)
         return int(env_cpu_count) if env_cpu_count else multiprocessing.cpu_count()
     except NotImplementedError:
         output.warn("multiprocessing.cpu_count() not implemented. Defaulting to 1 cpu")


Test patch:
diff --git a/conans/test/unittests/util/tools_test.py b/conans/test/unittests/util/tools_test.py
--- a/conans/test/unittests/util/tools_test.py
+++ b/conans/test/unittests/util/tools_test.py
@@ -547,6 +547,9 @@ def cpu_count_test(self):
         self.assertGreaterEqual(cpus, 1)
         with tools.environment_append({"CONAN_CPU_COUNT": "34"}):
             self.assertEquals(tools.cpu_count(output=output), 34)
+        with tools.environment_append({"CONAN_CPU_COUNT": "null"}):
+            with self.assertRaisesRegexp(ConanException, "Invalid CONAN_CPU_COUNT value"):
+                tools.cpu_count(output=output)
 
     def get_env_unit_test(self):
         """