Skip to content

Commit 31c1197

Browse files
improving terminating command function
1 parent 1c0b34e commit 31c1197

File tree

2 files changed

+33
-95
lines changed

2 files changed

+33
-95
lines changed

Diff for: errorhandling/cmdlets/Rad-Error-Utils.psm1

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ function Invoke-TerminatingCommand {
8181
)
8282

8383
Show-Output "Executing Command: [$Command]"
84-
$Result = & $Command
84+
$Result = & $Command 2>&1
8585

8686
# Check the execution status of the command
8787
if ($LASTEXITCODE -ne 0) {

Diff for: errorhandling/logging-functions.ipynb

+32-94
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
},
1616
{
1717
"cell_type": "code",
18-
"execution_count": 3,
18+
"execution_count": null,
1919
"metadata": {
2020
"dotnet_interactive": {
2121
"language": "pwsh"
@@ -38,7 +38,7 @@
3838
},
3939
{
4040
"cell_type": "code",
41-
"execution_count": 4,
41+
"execution_count": null,
4242
"metadata": {
4343
"dotnet_interactive": {
4444
"language": "pwsh"
@@ -88,7 +88,7 @@
8888
},
8989
{
9090
"cell_type": "code",
91-
"execution_count": 5,
91+
"execution_count": null,
9292
"metadata": {
9393
"dotnet_interactive": {
9494
"language": "pwsh"
@@ -117,7 +117,7 @@
117117
},
118118
{
119119
"cell_type": "code",
120-
"execution_count": 6,
120+
"execution_count": null,
121121
"metadata": {
122122
"dotnet_interactive": {
123123
"language": "pwsh"
@@ -126,20 +126,7 @@
126126
"kernelName": "pwsh"
127127
}
128128
},
129-
"outputs": [
130-
{
131-
"name": "stdout",
132-
"output_type": "stream",
133-
"text": [
134-
"\n",
135-
"\u001b[32;1mName \u001b[0m\u001b[32;1m Value\u001b[0m\n",
136-
"\u001b[32;1m---- \u001b[0m \u001b[32;1m-----\u001b[0m\n",
137-
"101 Error 101: Invalid parameter: {0}. Expected: {1}. Actual: {2}.\n",
138-
"500 An unexpected error occurred while executing the command: [{0}]. Er…\n",
139-
"\n"
140-
]
141-
}
142-
],
129+
"outputs": [],
143130
"source": [
144131
"Get-RadErrorMessages"
145132
]
@@ -157,7 +144,7 @@
157144
},
158145
{
159146
"cell_type": "code",
160-
"execution_count": 7,
147+
"execution_count": null,
161148
"metadata": {
162149
"dotnet_interactive": {
163150
"language": "pwsh"
@@ -188,7 +175,7 @@
188175
},
189176
{
190177
"cell_type": "code",
191-
"execution_count": 8,
178+
"execution_count": null,
192179
"metadata": {
193180
"dotnet_interactive": {
194181
"language": "pwsh"
@@ -227,7 +214,7 @@
227214
},
228215
{
229216
"cell_type": "code",
230-
"execution_count": 9,
217+
"execution_count": null,
231218
"metadata": {
232219
"dotnet_interactive": {
233220
"language": "pwsh"
@@ -270,7 +257,7 @@
270257
},
271258
{
272259
"cell_type": "code",
273-
"execution_count": 11,
260+
"execution_count": null,
274261
"metadata": {
275262
"dotnet_interactive": {
276263
"language": "pwsh"
@@ -308,7 +295,7 @@
308295
},
309296
{
310297
"cell_type": "code",
311-
"execution_count": 12,
298+
"execution_count": null,
312299
"metadata": {
313300
"dotnet_interactive": {
314301
"language": "pwsh"
@@ -346,7 +333,7 @@
346333
},
347334
{
348335
"cell_type": "code",
349-
"execution_count": 13,
336+
"execution_count": null,
350337
"metadata": {
351338
"dotnet_interactive": {
352339
"language": "pwsh"
@@ -395,7 +382,7 @@
395382
},
396383
{
397384
"cell_type": "code",
398-
"execution_count": 14,
385+
"execution_count": null,
399386
"metadata": {
400387
"dotnet_interactive": {
401388
"language": "pwsh"
@@ -440,7 +427,7 @@
440427
},
441428
{
442429
"cell_type": "code",
443-
"execution_count": 15,
430+
"execution_count": null,
444431
"metadata": {
445432
"dotnet_interactive": {
446433
"language": "pwsh"
@@ -489,7 +476,7 @@
489476
},
490477
{
491478
"cell_type": "code",
492-
"execution_count": 16,
479+
"execution_count": null,
493480
"metadata": {
494481
"dotnet_interactive": {
495482
"language": "pwsh"
@@ -543,7 +530,7 @@
543530
},
544531
{
545532
"cell_type": "code",
546-
"execution_count": 18,
533+
"execution_count": null,
547534
"metadata": {
548535
"dotnet_interactive": {
549536
"language": "pwsh"
@@ -588,7 +575,7 @@
588575
},
589576
{
590577
"cell_type": "code",
591-
"execution_count": 19,
578+
"execution_count": null,
592579
"metadata": {
593580
"dotnet_interactive": {
594581
"language": "pwsh"
@@ -623,7 +610,7 @@
623610
},
624611
{
625612
"cell_type": "code",
626-
"execution_count": 20,
613+
"execution_count": null,
627614
"metadata": {
628615
"dotnet_interactive": {
629616
"language": "pwsh"
@@ -675,7 +662,7 @@
675662
},
676663
{
677664
"cell_type": "code",
678-
"execution_count": 21,
665+
"execution_count": null,
679666
"metadata": {
680667
"dotnet_interactive": {
681668
"language": "pwsh"
@@ -710,7 +697,7 @@
710697
},
711698
{
712699
"cell_type": "code",
713-
"execution_count": 22,
700+
"execution_count": null,
714701
"metadata": {
715702
"dotnet_interactive": {
716703
"language": "pwsh"
@@ -745,7 +732,7 @@
745732
},
746733
{
747734
"cell_type": "code",
748-
"execution_count": 23,
735+
"execution_count": null,
749736
"metadata": {
750737
"dotnet_interactive": {
751738
"language": "pwsh"
@@ -780,7 +767,7 @@
780767
},
781768
{
782769
"cell_type": "code",
783-
"execution_count": 24,
770+
"execution_count": null,
784771
"metadata": {
785772
"dotnet_interactive": {
786773
"language": "pwsh"
@@ -811,7 +798,7 @@
811798
},
812799
{
813800
"cell_type": "code",
814-
"execution_count": 25,
801+
"execution_count": null,
815802
"metadata": {
816803
"dotnet_interactive": {
817804
"language": "pwsh"
@@ -847,7 +834,7 @@
847834
},
848835
{
849836
"cell_type": "code",
850-
"execution_count": 26,
837+
"execution_count": null,
851838
"metadata": {
852839
"dotnet_interactive": {
853840
"language": "pwsh"
@@ -893,7 +880,7 @@
893880
},
894881
{
895882
"cell_type": "code",
896-
"execution_count": 27,
883+
"execution_count": null,
897884
"metadata": {
898885
"dotnet_interactive": {
899886
"language": "pwsh"
@@ -930,12 +917,14 @@
930917
"source": [
931918
"## Next Steps\n",
932919
"\n",
933-
"Now let's run a script that utilizes these functions. This script will import the RAD modules, enable the logger, and then run the various functions in this notebook. We will then look at the log file to see what was logged."
920+
"Now let's run a script that utilizes these functions. This script will import the RAD modules, enable the logger, and then run the various functions in this notebook. We will then look at the log file to see what was logged.\n",
921+
"\n",
922+
"Make sure that you are running the following cells out of the `samples` directory:"
934923
]
935924
},
936925
{
937926
"cell_type": "code",
938-
"execution_count": 30,
927+
"execution_count": null,
939928
"metadata": {
940929
"dotnet_interactive": {
941930
"language": "pwsh"
@@ -946,12 +935,12 @@
946935
},
947936
"outputs": [],
948937
"source": [
949-
"Get-Location"
938+
"cd /workspaces/rad-powershell-cmdlets/errorhandling/samples"
950939
]
951940
},
952941
{
953942
"cell_type": "code",
954-
"execution_count": 31,
943+
"execution_count": null,
955944
"metadata": {
956945
"dotnet_interactive": {
957946
"language": "pwsh"
@@ -960,60 +949,9 @@
960949
"kernelName": "pwsh"
961950
}
962951
},
963-
"outputs": [
964-
{
965-
"data": {
966-
"text/plain": []
967-
},
968-
"metadata": {},
969-
"output_type": "display_data"
970-
},
971-
{
972-
"name": "stdout",
973-
"output_type": "stream",
974-
"text": [
975-
"\u001b[31;1m.: \u001b[0m/workspaces/rad-powershell-cmdlets/errorhandling/samples/Show-AzResourcesWithoutTag.ps1:25\u001b[0m\n",
976-
"\u001b[31;1m\u001b[0m\u001b[36;1mLine |\u001b[0m\n",
977-
"\u001b[31;1m\u001b[0m\u001b[36;1m\u001b[36;1m 25 | \u001b[0m . \u001b[36;1m.\\Init.ps1\u001b[0m\n",
978-
"\u001b[31;1m\u001b[0m\u001b[36;1m\u001b[36;1m\u001b[0m\u001b[36;1m\u001b[0m\u001b[36;1m | \u001b[31;1m ~~~~~~~~~~\u001b[0m\n",
979-
"\u001b[31;1m\u001b[0m\u001b[36;1m\u001b[36;1m\u001b[0m\u001b[36;1m\u001b[0m\u001b[36;1m\u001b[31;1m\u001b[31;1m\u001b[36;1m | \u001b[31;1mThe term '.\\Init.ps1' is not recognized as a name of a cmdlet, function, script file, or\u001b[0m\n",
980-
"\u001b[31;1m\u001b[0m\u001b[36;1m\u001b[36;1m\u001b[0m\u001b[36;1m\u001b[0m\u001b[36;1m\u001b[31;1m\u001b[31;1m\u001b[36;1m\u001b[31;1m\u001b[36;1m | \u001b[31;1mexecutable program. Check the spelling of the name, or if a path was included, verify that\u001b[0m\n",
981-
"\u001b[31;1m\u001b[0m\u001b[36;1m\u001b[36;1m\u001b[0m\u001b[36;1m\u001b[0m\u001b[36;1m\u001b[31;1m\u001b[31;1m\u001b[36;1m\u001b[31;1m\u001b[36;1m\u001b[31;1m\u001b[36;1m | \u001b[31;1mthe path is correct and try again.\u001b[0m\n",
982-
"[21:47:58 INF] # GETTING AZURE RESOURCES WITHOUT TAG\n",
983-
"\u001b[31;1m.: \u001b[0m/workspaces/rad-powershell-cmdlets/errorhandling/samples/Show-AzResourcesWithoutTag.ps1:30\u001b[0m\n",
984-
"\u001b[31;1m\u001b[0m\u001b[36;1mLine |\u001b[0m\n",
985-
"\u001b[31;1m\u001b[0m\u001b[36;1m\u001b[36;1m 30 | \u001b[0m . \u001b[36;1m.\\Init-Logger.ps1\u001b[0m -DetailedOutput:$DetailedOutput -SilentMode:$Sile …\u001b[0m\n",
986-
"\u001b[31;1m\u001b[0m\u001b[36;1m\u001b[36;1m\u001b[0m\u001b[36;1m\u001b[0m\u001b[36;1m | \u001b[31;1m ~~~~~~~~~~~~~~~~~\u001b[0m\n",
987-
"\u001b[31;1m\u001b[0m\u001b[36;1m\u001b[36;1m\u001b[0m\u001b[36;1m\u001b[0m\u001b[36;1m\u001b[31;1m\u001b[31;1m\u001b[36;1m | \u001b[31;1mThe term '.\\Init-Logger.ps1' is not recognized as a name of a cmdlet, function, script file,\u001b[0m\n",
988-
"\u001b[31;1m\u001b[0m\u001b[36;1m\u001b[36;1m\u001b[0m\u001b[36;1m\u001b[0m\u001b[36;1m\u001b[31;1m\u001b[31;1m\u001b[36;1m\u001b[31;1m\u001b[36;1m | \u001b[31;1mor executable program. Check the spelling of the name, or if a path was included, verify\u001b[0m\n",
989-
"\u001b[31;1m\u001b[0m\u001b[36;1m\u001b[36;1m\u001b[0m\u001b[36;1m\u001b[0m\u001b[36;1m\u001b[31;1m\u001b[31;1m\u001b[36;1m\u001b[31;1m\u001b[36;1m\u001b[31;1m\u001b[36;1m | \u001b[31;1mthat the path is correct and try again.\u001b[0m\n",
990-
"[21:47:58 INF] Connecting to Azure\n",
991-
"[21:47:58 INF] Executing Command: [ Connect-AzAccount ]\n",
992-
"\u001b[93mWARNING: Interactive authentication is not supported in this session, please run cmdlet 'Connect-AzAccount -UseDeviceAuthentication'.\u001b[0m\n",
993-
"[21:47:58 INF] Command executed successfully.\n",
994-
"[21:47:58 INF] Getting Az Resources\n",
995-
"[21:47:58 INF] Executing Command: [\n",
996-
" $resources = Get-AzResource\n",
997-
"]\n",
998-
"\u001b[31;1mGet-AzResource: \u001b[0m/workspaces/rad-powershell-cmdlets/errorhandling/samples/Show-AzResourcesWithoutTag.ps1:39\u001b[0m\n",
999-
"\u001b[31;1m\u001b[0m\u001b[36;1mLine |\u001b[0m\n",
1000-
"\u001b[31;1m\u001b[0m\u001b[36;1m\u001b[36;1m 39 | \u001b[0m $resources = \u001b[36;1mGet-AzResource\u001b[0m\n",
1001-
"\u001b[31;1m\u001b[0m\u001b[36;1m\u001b[36;1m\u001b[0m\u001b[36;1m\u001b[0m\u001b[36;1m | \u001b[31;1m ~~~~~~~~~~~~~~\u001b[0m\n",
1002-
"\u001b[31;1m\u001b[0m\u001b[36;1m\u001b[36;1m\u001b[0m\u001b[36;1m\u001b[0m\u001b[36;1m\u001b[31;1m\u001b[31;1m\u001b[36;1m | \u001b[31;1mRun Connect-AzAccount to login.\u001b[0m\n",
1003-
"[21:47:59 INF] Command executed successfully.\n"
1004-
]
1005-
},
1006-
{
1007-
"ename": "Error",
1008-
"evalue": "Command failed: SubmitCode: ./samples/Show-AzResourcesWithoutTag.ps1",
1009-
"output_type": "error",
1010-
"traceback": [
1011-
"Command failed: SubmitCode: ./samples/Show-AzResourcesWithoutTag.ps1"
1012-
]
1013-
}
1014-
],
952+
"outputs": [],
1015953
"source": [
1016-
"./samples/Show-AzResourcesWithoutTag.ps1"
954+
"./Show-AzResourcesWithoutTag.ps1"
1017955
]
1018956
}
1019957
],

0 commit comments

Comments
 (0)