Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error code formatting for windows returns Error message: Unknown error #7863

Closed
drew2a opened this issue Jan 26, 2024 · 3 comments
Closed

Error code formatting for windows returns Error message: Unknown error #7863

drew2a opened this issue Jan 26, 2024 · 3 comments
Assignees

Comments

@drew2a
Copy link
Contributor

drew2a commented Jan 26, 2024

We use os.strerror(exit_code) to transform an error code into its string representation, as documented in https://docs.python.org/3/library/os.html#os.strerror

def format_error_message(exit_code: int, exit_status: int) -> str:
message = f"The Tribler core has unexpectedly finished with exit code {exit_code} and status: {exit_status}."
if exit_code == 1:
string_error = "Application error"
else:
try:
string_error = os.strerror(exit_code)
except ValueError:
# On platforms where strerror() returns NULL when given an unknown error number, ValueError is raised.
string_error = 'unknown error number'
message += f'\n\nError message: {string_error}'
return message

However, it seems not to work on Windows OS. As seen in #7855, the error code -1073741819 was transformed to Error message: Unknown error instead of something like Application Error 0xc0000005 (Access Violation).

@drew2a
Copy link
Contributor Author

drew2a commented Feb 1, 2024

@drew2a
Copy link
Contributor Author

drew2a commented Feb 1, 2024

I've run out of ideas.

Here's what I've tried, besides the bare Win API call, which also does not work:

import ctypes
import os


def error_code_to_hex(error_code: int) -> str:
    """Convert a signed integer error code to a hexadecimal string."""
    v = error_code & 0xffffffff
    return hex(v)


def get_error_message(error_code: int):
    h = error_code_to_hex(error_code)
    print(f'\nError: {h}')
    print(f"\t{ctypes.FormatError(error_code)}")
    print(f"\t{ctypes.WinError(error_code)}")
    print(f'\t{os.strerror(error_code)}')


get_error_message(-1073741819)
get_error_message(-1073740940)
get_error_message(1)
Error: 0xc0000005
        <no description>
        [WinError -1073741819] <no description>
        Unknown error

Error: 0xc0000374
        <no description>
        [WinError -1073740940] <no description>
        Unknown error

Error: 0x1
        Incorrect function.
        [WinError 1] Incorrect function.
        Operation not permitted

Repositories attempting to achieve the same goal:

@drew2a
Copy link
Contributor Author

drew2a commented Feb 7, 2024

@drew2a drew2a closed this as completed Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

1 participant