question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

interpolation in assertion failure message

See original GitHub issue

[@gavinking] When we implemented assertions, we left one issue for later: how to interpolate expressions into the assertion failure message. Right now, we can write:

"exponent must be non-negative"
assert (power>=0);

Where the string literal is an abbreviated doc annotation. I’ve defended this solution on the grounds that it lets ceylondoc include the preconditions on parameters in its generated documentation. However, in truth, we’re eventually going to need interpolation here. So the question is: what should the syntax be. Clearly, the following is one possibility:

"exponent ``power`` must be non-negative"
assert (power>=0);

Could ceylondoc do something reasonable with this? I don’t see why not. But is it just to “weird” to suddenly let you have interpolation in a doc string, all of a sudden, in one special case?

Alternatively, we could let you write something like this:

assert (power>=0) "exponent ``power`` must be non-negative";

or this:

assert (power>=0) => "exponent ``power`` must be non-negative";

The => is not strictly necessary. But for some reason I find it more natural to format across multiple lines. This:

assert (power>=0) 
        "exponent ``power`` must be non-negative";

is to me less natural than this:

assert (power>=0) 
        => "exponent ``power`` must be non-negative";

Whatever, either option would be acceptable to me.

WDYT?

[Migrated from ceylon/ceylon-spec#586]

Issue Analytics

  • State:closed
  • Created 11 years ago
  • Comments:21 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
gavinkingcommented, Feb 24, 2017

Done!

1reaction
gavinkingcommented, Feb 23, 2017

I have implemented support for this in the typechecker. However, the backends need to be modified to support this (which I assume is a pretty trivial change).

@tombentley? @chochos?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Chapter 4. Interpolating constraint error messages
Message interpolation is the process of creating error messages for violated Bean Validation constraints. In this chapter you will learn how such messages ......
Read more >
Assertions, and why do we put message? - Using Swift - Swift Forums
The output from a failed assertion consists of Assertion failed: , then your custom message, then the location. In a playground, let age...
Read more >
xml - How to fix 'Assertion failure:true' even if the expected and ...
If you don't use a Regular Expression for data validation and it is rather a normal String - just untick 'Match as regular...
Read more >
Dissecting Interpolated Strings Improvements in C# 10
Assert with a custom error message in a loop and not be afraid of performance issues caused by excessive message construction! private int ......
Read more >
UsingAssertionsEffectively - Python Wiki
Python's assert statement helps you find bugs more quickly and with ... Instead, you should raise an exception, or print an error message, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found