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.

Ideas for skipping cleanup on error?

See original GitHub issue

Just ran an apply/destroy cycle through tftest, where on destroy I ran into a timing error when waiting for a resource to change to the expected state:

Error: Error waiting for VPC Peering Connection (pcx-....) to be deleted: timeout while waiting for state to become 'rejected, deleted' (last state: 'active', timeout: 1m0s)

Ok, not great, but no big deal, just go into the test directory and re-run destroy… Except, the tfstate file is gone, so can’t do that!

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
grahamharcommented, Jan 11, 2022

Yes you get a test pass which in our use case is what we want.

If that is not what you want add a pytest.fail to the except block

1reaction
grahamharcommented, Jan 11, 2022

@ludoo Sorry I probably should have provided more explanation, let me provide a few examples of how I think the approach I suggested helps.

  1. Issue with Terraform code under test that results in a failure under the apply phase, this captures the exception thrown from the apply and runs a destroy which should clean up any resources already created. As Terraform in many cases doesn’t validate parameters it’s easy to get 400 type response back which halt execution leaving some resources created.
  2. Issue in Destroy caused by a timeout, generally when this happens a second run of destroy would rectify this, not perfect but we’ve found this to be the case.
  3. Occasionally we get race conditions like a policy on an S3 bucket trying to be deleted while another S3 operation is underway, again the second attempt in the except block normally resolves this.

I agree it is probably a good idea to set cleanup_on_exit to False.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Best practices for non-local exit with cleanup in C?
What is considered best practice for aborting on errors in C? In our code base we currently have a pattern using #define CHECKERROR(code)...
Read more >
8 Effective Data Cleaning Techniques for Better Data
1. Remove Duplicates · 2. Remove Irrelevant Data · 3. Standardize Capitalization · 4. Convert Data Types · 5. Clear Formatting · 6....
Read more >
Better error handling in Golang: Theory and practical tips
Don't panic() ! It's a good life lesson in general, but especially important when writing Go code. Long-running applications should handle errors gracefully ......
Read more >
9 Best Practices to Handle Java Exceptions - Stackify
1. Clean Up Resources in a Finally Block or Use a Try-With-Resource Statement · 2. Prefer Specific Exceptions · 3. Document the Exceptions...
Read more >
Top 15 C++ Exception handling mistakes and how to avoid ...
MEASURE for yourself and then make a call. Think about what you're losing out by not using exceptions. If you hit a performance...
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