Comments (4)
Fix is now live in 4.23.0
from posh-acme.
Hey @joshooaj, thanks for the heads up. PowerShell error handling is definitely something I still have a hard time getting "right". If I recall correctly, most of these instances of ThrowTerminatingError
used to be just plain throw
prior to the 4.0 release because I didn't know any better in the earlier versions. But errors were ugly and pointed to internal logic where it wasn't necessary or relevant for the user.
So I went looking for a better way and wound up on Kevin Marquette's excellent, PowerShell: Everything you wanted to know about exceptions. But clearly, I didn't quite get it right in 4.x. In particular, I apparently missed this:
One nuance of $PSCmdlet.ThrowTerminatingError() is that it creates a terminating error within your Cmdlet but it turns into a non-terminating error after it leaves your Cmdlet. This leaves the burden on the caller of your function to decide how to handle the error. They can turn it back into a terminating error by using -ErrorAction Stop or calling it from within a try{...}catch{...}.
I think it's also the reason your 1..4
test also still runs 4 times instead of 1 even if the module function gets fixed so it only produces a single terminating error. But even adding -EA Stop
to the call doesn't seem to halt the loop for me. To get the loop to stop after 1 iteration, I needed to do one of the following:
- Wrap the whole thing in try/catch
- Wrap the inner loop contents in a try/catch where the code in the catch broke the loop (throw, ThrowTerminatingError, or return)
- Change the
$ErrorActionPreference
variable toStop
instead of the defaultContinue
.
from posh-acme.
Forgot to add, I'll work on fixing the basic problem with the multiple errors where there should only be one.
from posh-acme.
Kevin's blog is such a great resource - I should have known to look there first to refresh my memory on the nuances of error handling!
I suppose it makes sense in some cases to hide inner errors from the user - sort of treating the errors as an "interface" and only exposing what is important. As a developer I'm biased in that I want to see where the actual error is thrown (file and line) and I'm less concerned about where it was re-thrown since that should ultimately be in the stack trace.
I'll have to give that post another read through and think about using ThrowTerminatingError()
in my code when exceptions come from private functions so that the error source always looks to be from public functions.
This is a super unimportant issue really, just cosmetic - thanks for taking the time to respond 😎
from posh-acme.
Related Issues (20)
- WEDOS DNS support ? HOT 5
- Multiple Accounts with DigiCert HOT 4
- Cloudflare Plug In fails to convert String to SecureString HOT 9
- Submit-Renewal doesn't appear to follow ErrorAction HOT 2
- Is there a full list of supported fields for -Subject? HOT 3
- 404 on Submit-ChallengeValidation when using LetsEncrypt Staging HOT 1
- OVH plugin using DnsAlias fails if not using subdomain of the OVHdomain HOT 2
- Trying to use ZeroSSL HOT 4
- Problem with OVH plugin for creating/renewing certificates HOT 8
- Error requesting certificate with WebRoot plugin HOT 5
- FullChainFile doesn't contain ISRG Root X1 HOT 9
- Active24 plugin no longer working HOT 25
- Pull cert into local certificate store using FQDN and Subsequent renew HOT 5
- CmdLets Repeatedly asking for DNS Text Records HOT 3
- OVH plugin is not compatible with PowerShell 5.1
- DNSimple Plugin not removing dns challange HOT 3
- DNSimple Plugin regression HOT 3
- DNSPod Argument Names HOT 3
- Gandi API change HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from posh-acme.