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

Add precondition messages #111

Closed
oscbyspro opened this issue May 10, 2023 · 2 comments
Closed

Add precondition messages #111

oscbyspro opened this issue May 10, 2023 · 2 comments
Labels
brrr such code, much wow
Milestone

Comments

@oscbyspro
Copy link
Owner

oscbyspro commented May 10, 2023

I suppose precondition messages are nice to have. I would consider it a small quality-of-life improvement, for when things go wrong. Looking at [U]Int128 (#109), the "overflow in [x]" precondition message format seems descriptive enough.

@oscbyspro oscbyspro added the brrr such code, much wow label May 10, 2023
@oscbyspro oscbyspro added this to the v2.3.0 milestone May 10, 2023
@oscbyspro
Copy link
Owner Author

I suppose messages are only really useful for programmer inputs.

assert(2 < 3, "something is broken") // useless message

@oscbyspro
Copy link
Owner Author

oscbyspro commented May 16, 2023

Something like this might be a bit more maintainable:

precondition(!overflow, callsiteOverflowInfo())
func callsiteOverflowInfo(function: StaticString = #function, file: StaticString = #file, line: UInt = #line) -> String {
    "overflow in \(function) at \(file):\(line)"
}

oscbyspro added a commit that referenced this issue May 16, 2023
oscbyspro added a commit that referenced this issue Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
brrr such code, much wow
Projects
None yet
Development

No branches or pull requests

1 participant