Skip to content

Commit ea6517a

Browse files
authored
Merge pull request #39 from aslamcodes/fix/command-out-error-context
Fix/command out error context
2 parents c450aba + b905979 commit ea6517a

5 files changed

Lines changed: 45 additions & 30 deletions

File tree

internal/backend/local_test.go

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ func TestGetConfig(t *testing.T) {
2424

2525
expected := config.Config{
2626
Platform: "windows",
27+
2728
Image: config.Image{
2829
Name: "example_image",
2930
DisplayName: "example image",
@@ -33,25 +34,39 @@ func TestGetConfig(t *testing.T) {
3334
Tags: []string{"team:infra", "env:dev"},
3435
DryRun: false,
3536
},
37+
3638
Installers: []config.Installer{
3739
{Executable: "powershell", InstallScript: "Write-Host \"Hello World\"\n"},
3840
{Executable: "powershell", InstallScript: "echo \"Setting up environment\"\n"},
3941
},
40-
Files: []config.File{
41-
{Path: `C:\AppStream\Scripts\Start-System.ps1`, Content: "Write-EventLog -LogName Application -Source AppStream -EventID 100 -Message \"System session start\"\n"},
42-
{Path: `C:\AppStream\Scripts\Start-User.ps1`, Content: "Write-Host \"User profile initialization\"\n"},
43-
{Path: `C:\AppStream\Scripts\End-System.ps1`, Content: "Write-EventLog -LogName Application -Source AppStream -EventID 200 -Message \"System cleanup\"\n"},
44-
{Path: `C:\AppStream\Scripts\End-User.ps1`, Content: "Write-Host \"User session cleanup\"\n"},
45-
},
4642

4743
Catalogs: []config.CatalogConfig{
4844
{
4945
Name: "Notepad",
5046
Path: `C:\Windows\System32\notepad.exe`,
5147
DisplayName: "Notepad",
5248
Parameters: "",
53-
IconPath: `C:\Windows\System32\notepad.exe`,
54-
WorkingDir: `C:\Windows\System32`,
49+
IconPath: "",
50+
WorkingDir: "",
51+
},
52+
},
53+
54+
Files: []config.File{
55+
{
56+
Path: `C:\AppStream\Scripts\Start-System.ps1`,
57+
Content: "Write-EventLog -LogName Application -Source AppStream -EventID 100 -Message \"System session start\"\n",
58+
},
59+
{
60+
Path: `C:\AppStream\Scripts\Start-User.ps1`,
61+
Content: "Write-Host \"User profile initialization\"\n",
62+
},
63+
{
64+
Path: `C:\AppStream\Scripts\End-System.ps1`,
65+
Content: "Write-EventLog -LogName Application -Source AppStream -EventID 200 -Message \"System cleanup\"\n",
66+
},
67+
{
68+
Path: `C:\AppStream\Scripts\End-User.ps1`,
69+
Content: "Write-Host \"User session cleanup\"\n",
5570
},
5671
},
5772

@@ -60,31 +75,32 @@ func TestGetConfig(t *testing.T) {
6075
Executables: []config.Executable{
6176
{
6277
Context: "system",
63-
Filename: `C:\AppStream\Scripts\Start-System.ps1`,
64-
Arguments: "-Init",
78+
Filename: `C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe`,
79+
Arguments: "-Init -File C:\\AppStream\\Scripts\\Start-System.ps1",
6580
S3LogEnabled: true,
6681
},
6782
{
6883
Context: "user",
69-
Filename: `C:\AppStream\Scripts\Start-User.ps1`,
70-
Arguments: "-UserSetup",
84+
Filename: `C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe`,
85+
Arguments: "-UserSetup -File C:\\AppStream\\Scripts\\Start-User.ps1",
7186
S3LogEnabled: true,
7287
},
7388
},
7489
WaitingTime: 60,
7590
},
91+
7692
SessionTermination: config.SessionConfig{
7793
Executables: []config.Executable{
7894
{
7995
Context: "system",
80-
Filename: `C:\AppStream\Scripts\End-System.ps1`,
81-
Arguments: "-Cleanup",
96+
Filename: `C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe`,
97+
Arguments: "-Init -File C:\\AppStream\\Scripts\\Start-System.ps1",
8298
S3LogEnabled: true,
8399
},
84100
{
85101
Context: "user",
86-
Filename: `C:\AppStream\Scripts\End-User.ps1`,
87-
Arguments: "-CleanupUser",
102+
Filename: `C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe`,
103+
Arguments: "-UserSetup -File C:\\AppStream\\Scripts\\Start-User.ps1",
88104
S3LogEnabled: true,
89105
},
90106
},

internal/service/catalog_service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func (svc *UpdateStackCatalogSvc) UpdateStackCatalog(c config.CatalogConfig) err
2828
output, err := cmd.CombinedOutput()
2929

3030
if err != nil {
31-
return err
31+
return fmt.Errorf("error executing command: %s\nouput: %s\nerror: %w", cmd.String(), output, err)
3232
}
3333

3434
fmt.Println(string(output))

internal/service/image_build_service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func (i *ImageBuildSvc) BuildImage(image config.Image) error {
2929
output, err := cmd.CombinedOutput()
3030

3131
if err != nil {
32-
return err
32+
return fmt.Errorf("error executing command: %s\nouput: %s\nerror: %w", cmd.String(), output, err)
3333
}
3434

3535
fmt.Println(string(output))

internal/service/installer_service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func (s *InstallerSvc) RunScript(exe string, args []string, filePath string) err
6161
out, err := cmd.CombinedOutput()
6262

6363
if err != nil {
64-
return fmt.Errorf("command failed: %w\noutput: %s", err, out)
64+
return fmt.Errorf("error executing command: %s\nouput: %s\nerror: %w", cmd.String(), out, err)
6565
}
6666

6767
fmt.Println(string(out))

testdata/config_win.yaml

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ catalog:
1313
path: "C:\\Windows\\System32\\notepad.exe"
1414
display_name: "Notepad"
1515
parameters: ""
16-
icon_path: "C:\\Windows\\System32\\notepad.exe"
17-
working_dir: "C:\\Windows\\System32"
16+
icon_path: ""
17+
working_dir: ""
1818

1919
registry_config:
2020
- path: "HKEY_LOCAL_MACHINE\\Software\\MyApp"
@@ -48,27 +48,26 @@ session_scripts:
4848
session_start:
4949
executables:
5050
- context: "system"
51-
filename: "C:\\AppStream\\Scripts\\Start-System.ps1"
52-
arguments: "-Init"
51+
filename: "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"
52+
arguments: "-Init -File C:\\AppStream\\Scripts\\Start-System.ps1"
5353
s3LogEnabled: true
5454

5555
- context: "user"
56-
filename: "C:\\AppStream\\Scripts\\Start-User.ps1"
57-
arguments: "-UserSetup"
56+
filename: "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"
57+
arguments: "-UserSetup -File C:\\AppStream\\Scripts\\Start-User.ps1"
5858
s3LogEnabled: true
59-
6059
waitingTime: 60
6160

6261
session_termination:
6362
executables:
6463
- context: "system"
65-
filename: "C:\\AppStream\\Scripts\\End-System.ps1"
66-
arguments: "-Cleanup"
64+
filename: "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"
65+
arguments: "-Init -File C:\\AppStream\\Scripts\\Start-System.ps1"
6766
s3LogEnabled: true
6867

6968
- context: "user"
70-
filename: "C:\\AppStream\\Scripts\\End-User.ps1"
71-
arguments: "-CleanupUser"
69+
filename: "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"
70+
arguments: "-UserSetup -File C:\\AppStream\\Scripts\\Start-User.ps1"
7271
s3LogEnabled: true
7372

7473
waitingTime: 60

0 commit comments

Comments
 (0)