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.

Sanity function to check for empty error output

See original GitHub issue

I was creating a test in reframe, and hit a case where my sanity pattern was found in the output, yet there were also warnings going to stderr. Of course, if you expect a test to produce no warnings or errors, it makes a lot of sense to add a sanity check that checks if the error output is emtpy. I could however not find a default sanity test that does something like this…

Did I overlook it, or is it not implemented? If it isn’t implemented, would it be an idea (feature request coming up here) to add such a sanity function? It seems like a pretty generic case one may want to check.

I now did

@sn.sanity_function
def assert_iostream_empty(iostream):
    return sn.assert_not_found(r'.+', iostream)
...
self.sanity_patterns = sn.all([
    assert_iostream_empty(self.stderr),
    ...
])

This seems to work, but I can imagine there may be more elegant methods (and maybe a more low level implementation of checking for an emtpy file than a generic regex is more robust too).

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
casparvlcommented, Jun 25, 2020

Ah cool, that is indeed more robust.

By the way, I now also print the first part of the error output

@sn.sanity_function
def assert_file_empty(file):
    try:
        if sn.assert_not_found(r'^$', file):
            return True
    except SanityError:
        with open(file, 'r') as errorfile:
            errMsg = errorfile.read()
        raise SanityError("File {0} not empty.\nFirst 300 chars:\n{1}".format(file, errMsg[0:300])) from None

For me, printing a few lines from the error output really helps to quickly identify why the sanity check fails, making it a bit faster than having to browse to the file.

Anyway, thanks for the improved regex suggestion. It all works for me now, I just figured I’d share the idea in case you think it can help more people and want to implement it as something more standardized 😃

0reactions
casparvlcommented, Jul 5, 2020

Yes, thanks! I will close it 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sanity function to check for empty error output #1390 - GitHub
Hi @casparvl, you can use sn.assert_found(r'^$', self.stderr) which will match only when stderr is completely empty.
Read more >
Functions - Sanity.io
Takes a variable number of arguments of any type and returns the first non- null argument if any, otherwise null - e.g., coalesce(null,...
Read more >
Validation - Sanity.io
Describes how to validate documents within the content studio.
Read more >
Operators - Sanity.io
GROQ supports the use of the following logical operators: ... The operand – the value that the operator evaluates – must be a...
Read more >
JavaScript - Sanity.io
If you want to create a document if it does not already exist, but fall back without error if it does, you can...
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