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

[Feature Request] Support for errno in external_call to Improve Error Handling #2532

Open
1 task done
dayeondev opened this issue May 5, 2024 · 2 comments
Open
1 task done
Labels
enhancement New feature or request mojo-repo Tag all issues with this label

Comments

@dayeondev
Copy link

Review Mojo's priorities

What is your request?

Please add the ability to access errno after using external_call in Mojo. This enhancement will allow for more detailed error handling and reporting after system function calls.

What is your motivation for this change?

Currently, while Mojo's external_call facilitates the invocation of system library functions, it lacks the capability to access error codes (errno) after a call fails. This limitation significantly restricts error management. For instance, operations such as file deletion or library closure provide only the status of failure without any information on the cause of the error. This lack of detailed error information is a major hindrance for developers in diagnosing issues and providing useful feedback to users.

Examples:

  • In stdlib/src/builtin/io.mojo:
_ = external_call["fclose", Int32](self.handle)
_ = external_call["fflush", Int32](fd)
_ = external_call["vprintf", Int32](x.data, arg_ptr.bitcast[UnsafePointer[NoneType]]())
  • In stdlib/src/os/os.mojo:
_ = external_call["closedir", Int32](self._handle)
var error = external_call["unlink", Int](path._as_ptr())
  • In stdlib/src/sys/ffi.mojo:
_ = external_call["dlclose", Int](self.handle)
  • In stdlib/src/time/time.mojo:
_ = external_call["clock_gettime", Int32](Int32(clockid), UnsafePointer.address_of(ts))
_ = external_call["nanosleep", Int32](req, rem)

Any other details?

The implementation should include the following minimum functional attributes:

  • Direct access to errno or through a standardized error handling interface.
  • A mechanism to capture and return error states in a consistent manner across platforms.
  • The ability to return detailed error messages based on error codes, similar to the strerror function in C, either supported directly by Mojo or implemented internally.

Other considerations:

  • Enhancing error handling capabilities will contribute to strengthening Mojo's flexibility and reliability as a systems programming language.
  • Improving error management will help developers build more robust and stable applications and improve the end-user experience.
@dayeondev dayeondev added enhancement New feature or request mojo-repo Tag all issues with this label labels May 5, 2024
@JoeLoser JoeLoser added the mojo-stdlib Tag for issues related to standard library label May 5, 2024
@JoeLoser
Copy link
Collaborator

JoeLoser commented May 5, 2024

@Mogball what's the priority of global variable support?

@Mogball
Copy link
Collaborator

Mogball commented May 6, 2024

@jopamer

@ematejska ematejska added mojo-repo Tag all issues with this label and removed mojo-stdlib Tag for issues related to standard library mojo-repo Tag all issues with this label labels May 6, 2024
@ematejska ematejska added the mojo-stdlib Tag for issues related to standard library label May 7, 2024 — with Linear
@JoeLoser JoeLoser added mojo-lang Tag for all issues related to language. and removed mojo-stdlib Tag for issues related to standard library mojo-lang Tag for all issues related to language. labels May 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request mojo-repo Tag all issues with this label
Projects
None yet
Development

No branches or pull requests

4 participants