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

Error handling koans #153

Merged
merged 8 commits into from Apr 21, 2019
Merged

Error handling koans #153

merged 8 commits into from Apr 21, 2019

Conversation

vexx32
Copy link
Owner

@vexx32 vexx32 commented Apr 16, 2019

PR Summary

Add error handling koans!

TODO

Error Handling in PowerShell

PowerShell handles errors via the System.Management.Automation.ErrorRecord class. These objects form
the basic unit of "an error" in PowerShell.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seeing this sentence after coming here to learn about errors I'd be very confused. It is overly technical but also abstract. What does >>basic unit of "an error"<< even mean? I'd rephrase it with a beginner in mind, without trying to squeeze too much ideas into the first sentence they see.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, good point. Maybe something more like Each error is represented in PowerShell by a corresponding ErrorRecord object.?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IDK, is that the first thing to learn about errors? I'd start from the terminating, non-terminating categorisation. You are mentioning ErrorRecord before the first task, so I'd just delete this.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure it would make any sense to talk about errors at all in PowerShell before at least giving an overview of what they are... 😕

PowerShell handles errors via the System.Management.Automation.ErrorRecord class. These objects form
the basic unit of "an error" in PowerShell.

Errors can be flagged as terminating or non-terminating based on a few different criteria, largely
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flagged by who, based on which criteria? :) Be more authoritative, you are the teacher here. It does not matter that you leave out some detail or an edge-case. Give solid facts first. "Errors in PowerShell are terminating and non-terminating. The type of error that a command throws depends on the severity of the error. If the command cannot continue it throws a terminating error, if it can continue it throws a non-terminating error.

example 1: a built-in cmdlet throwing terminating error
example 2: a built-in cmdlet throwing non-terminating error

To handle terminating errors we use try/catch etc...

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Authoritative is a bit much I feel, but I know what you mean. I'll see how I can rephrase this 😄

metadata that you can work with if you come across an error.
#>
BeforeAll {
$Record = try {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd call this ErrorRecord

Note that specifying the exception type is optional. A "generic" catch block (no exception type
specified) will simply catch everything. If you know the errors you're looking for, it's often
best to only catch the ones you're expecting. If something else happens, you might make matters
worse by handling that the same way as the errors you were expecting.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A short example of bad error handling practice might be useful here e.g. try { throw [InvalidOperationException]"Cannot write into file log.txt" } catch { Write-Host "Cannot connect to network" }

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good idea, thanks!

@vexx32 vexx32 added Category-Koans Invoking the Great Doubt PR-Needs-Review 🔍 Let's take a closer look! labels Apr 20, 2019
@vexx32
Copy link
Owner Author

vexx32 commented Apr 20, 2019

@nohwnd if you have a moment to check through my latest changes and let me know if there's anything more that needs tinkering with, I'd greatly appreciate it <3

@vexx32 vexx32 merged commit 369daae into master Apr 21, 2019
@vexx32 vexx32 deleted the ErrorHandlingKoans branch April 21, 2019 04:37
@vexx32 vexx32 mentioned this pull request May 8, 2019
@vexx32 vexx32 added this to Done in Koan Topic Tracking May 8, 2019
@vexx32 vexx32 removed the PR-Needs-Review 🔍 Let's take a closer look! label Sep 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category-Koans Invoking the Great Doubt
Projects
Development

Successfully merging this pull request may close these issues.

None yet

2 participants