Skip to content

Commit

Permalink
Changed output of error messages slightly to show more error details …
Browse files Browse the repository at this point in the history
…and bumped version number in markdown readme
  • Loading branch information
echalone committed Jul 27, 2023
1 parent 165704e commit 76c163a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
6 changes: 4 additions & 2 deletions PowerShell/Modules/TUN.Logging/TUN.Logging.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
Module Name: TUN.Logging
Module Guid: eeac1534-25a5-4429-a073-17ec769525f5
Module Version: 1.1.2
Module Version: 1.1.4
Locale: en-US
---

Expand All @@ -15,7 +15,7 @@ Provides easy to use file and mail logging. Documentation of module at https://g
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/

## Module Metadata
* Module version: 1.1.2
* Module version: 1.1.4
* Module GUID: eeac1534-25a5-4429-a073-17ec769525f5
* Author: Markus Szumovski
* Company: ThingsUNeed
Expand All @@ -34,6 +34,8 @@ V 1.0.5: Bugfixes for logging from console or function, added logging of user<br
V 1.1.0: Bugfixes for Linux, now compatible with Linux Powershell Core<br/>
V 1.1.1: Bugfixing fallback color<br/>
V 1.1.2: Updated markdown help and added examples<br/>
V 1.1.3: Changed output of error messages slightly to show more error details<br/>
V 1.1.4: Bumped version number in markdown readme<br/>

### Required Modules
* TUN.Credentials (1.1.0)
Expand Down
8 changes: 5 additions & 3 deletions PowerShell/Modules/TUN.Logging/TUN.Logging.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# Generated by: Markus Szumovski
#
# Generated on: 29.01.2021
# Generated on: 27.07.2023
#

@{
Expand All @@ -12,7 +12,7 @@
RootModule = 'TUN.Logging.psm1'

# Version number of this module.
ModuleVersion = '1.1.2'
ModuleVersion = '1.1.4'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down Expand Up @@ -124,7 +124,9 @@ V 1.0.4: Bumped required module version
V 1.0.5: Bugfixes for logging from console or function, added logging of user
V 1.1.0: Bugfixes for Linux, now compatible with Linux Powershell Core
V 1.1.1: Bugfixing fallback color
V 1.1.2: Updated markdown help and added examples'
V 1.1.2: Updated markdown help and added examples
V 1.1.3: Changed output of error messages slightly to show more error details
V 1.1.4: Bumped version number in markdown readme'

# Prerelease string of this module
# Prerelease = ''
Expand Down
18 changes: 13 additions & 5 deletions PowerShell/Modules/TUN.Logging/TUN.Logging.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -1841,8 +1841,16 @@ function Write-ErrorLog {
$strErrorMessage = ""

if($Err -and $Err.InvocationInfo -and !$NoErrorDetails.IsPresent) {
$strErrorMessage += "`r`nScript: $($Err.InvocationInfo.ScriptName), Line: $($Err.InvocationInfo.ScriptLineNumber), Offset: $($Err.InvocationInfo.OffsetInLine)`r`n"
$strErrorMessage += "`r`n$($Err.InvocationInfo.Line)`r`n"
if($null -ne $Err.ErrorDetails) {
if(![string]::IsNullOrWhiteSpace($Err.ErrorDetails.Message)) {
$strErrorMessage += "Error-Details: $($Err.ErrorDetails.Message);`r`n"
}
if(![string]::IsNullOrWhiteSpace($Err.ErrorDetails.RecommendedAction)) {
$strErrorMessage += "Recommended action: $($Err.ErrorDetails.RecommendedAction);`r`n"
}
}
$strErrorMessage += "`r`nScript: $($Err.InvocationInfo.ScriptName), Line: $($Err.InvocationInfo.ScriptLineNumber), Offset: $($Err.InvocationInfo.OffsetInLine);`r`n"
$strErrorMessage += "`r`n$($Err.InvocationInfo.Line);`r`n"
}
$strErrorMessage += $Message

Expand All @@ -1851,23 +1859,23 @@ function Write-ErrorLog {
}

if($Exception) {
$strErrorMessage += "Error-Details: $($Exception.GetType().FullName), $($Exception.Message)" # - CategoryInfo: $($Err.CategoryInfo)"
$strErrorMessage += "Exception-Details: $($Exception.GetType().FullName), $($Exception.Message);" # - CategoryInfo: $($Err.CategoryInfo)"
}

#and now let's send the error message to the error stream
if($Err) {
if(!$NoOut.IsPresent) {
Write-Error $strErrorMessage -Category $Category -ErrorId $Err.FullyQualifiedErrorId
}
$strErrorMessage = ($strErrorMessage + " (Err-Category: $Category, Err-Id: $($Err.FullyQualifiedErrorId))")
$strErrorMessage = ($strErrorMessage + " (Err-Category: $Category, Err-Id: $($Err.FullyQualifiedErrorId));")
Write-Log -NoLog:$NoLog -AddTimestamp:$AddTimestamp -Force:$Force -IsError -Message $strErrorMessage
Write-MailLog -NoMail:$NoMail -Force:$ForceMail -IsError -Message $strErrorMessage
}
else {
if(!$NoOut.IsPresent) {
Write-Error $strErrorMessage -Category $Category
}
$strErrorMessage = ($strErrorMessage + " (Err-Category: $Category)")
$strErrorMessage = ($strErrorMessage + " (Err-Category: $Category);")
Write-Log -NoLog:$NoLog -AddTimestamp:$AddTimestamp -Force:$Force -IsError -Message $strErrorMessage
Write-MailLog -NoMail:$NoMail -Force:$ForceMail -IsError -Message $strErrorMessage
}
Expand Down

0 comments on commit 76c163a

Please sign in to comment.