-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prints a system error message on the standard error then exits with an error status. Raising an exception should always be preferred but there are a few cases where we can't allocate any memory (e.g. stop the world) and still need to fail when reaching a system error.
- Loading branch information
1 parent
da33258
commit 6c34494
Showing
5 changed files
with
48 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module Crystal::System | ||
# Prints a system error message on the standard error then exits with an error | ||
# status. | ||
# | ||
# You should always prefer raising an exception, built with | ||
# `RuntimeError.from_os_error` for example, but there are a few cases where we | ||
# can't allocate any memory (e.g. stop the world) and still need to fail when | ||
# reaching a system error. | ||
def self.panic(syscall_name : String, error : Errno | WinError | WasiError) : NoReturn | ||
System.print_error("%s failed with ", syscall_name) | ||
error.unsafe_message { |slice| System.print_error(slice) } | ||
System.print_error(" (%s)\n", error.to_s) | ||
|
||
LibC._exit(1) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters