easy +10 pts

Error message formatter

Format an error message from parts and context with a clear contract.

Write a function `format_error_message(code: str, context: str | None = None) -> str` that returns an error message string built as follows: 1. Start with the error code in uppercase, prefixed by `ERROR_`. For example, if `code` is `"timeout"`, the prefix becomes `ERROR_TIMEOUT`. 2. If `context` is provided (not `None`) and after stripping it is non-empty, append `": "` and the stripped context. 3. If `context` is `None` or empty/whitespace only, append `": Unknown error"` instead. Return the resulting string. The function must accept only strings (or `None` for context); no other types will be passed.

Constraints

- `code` is a non-empty string composed of lowercase letters, digits, and underscores. - `context` is either `None` or a string (possibly empty or whitespace). - Do not modify the original context; only use its stripped form. - The code is already intended to be lowercase, but you must still convert to uppercase.

Example

```python
>>> format_error_message("timeout")
'ERROR_TIMEOUT: Unknown error'
>>> format_error_message("auth_failed", "Invalid token")
'ERROR_AUTH_FAILED: Invalid token'
>>> format_error_message("db", "  connection refused  ")
'ERROR_DB: connection refused'
```
10 points ~15 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Use `code.upper()` to get the uppercase version.
Check if `context` is not None and `context.strip()` is non-empty before using it.
Remember to strip the context when appending it.
The fallback message is exactly `': Unknown error'`.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.