Skip to content

Commit 7d6f3db

Browse files
author
Andrew Steurer
committed
improving error messages, updating .gitignore and README
Signed-off-by: Andrew Steurer <[email protected]>
1 parent 788df9d commit 7d6f3db

File tree

7 files changed

+38
-33
lines changed

7 files changed

+38
-33
lines changed

.gitignore

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
otel-plugin
2-
otel
1+
otel
2+
*.json
3+
*.tar.gz

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Alternatively, use the `spin pluginify` plugin to install from a fresh build. Th
3434
```sh
3535
spin plugins install pluginify
3636
go build -o otel
37-
spin pluginify install
37+
spin pluginify --install
3838
```
3939

4040
# Usage

cmd/cleanup.go

+4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ func getIDs(dockerOutput []byte) []string {
3737
}
3838

3939
func cleanUp() error {
40+
if err := checkDocker(); err != nil {
41+
return err
42+
}
43+
4044
fmt.Println("Stopping Spin OTel Docker containers...")
4145

4246
getContainers := exec.Command("docker", "ps")

cmd/root.go

+18-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cmd
33
import (
44
"fmt"
55
"os"
6+
"os/exec"
67
"path"
78

89
open "github.com/fermyon/otel-plugin/cmd/open"
@@ -28,20 +29,34 @@ func setOtelConfigPath() error {
2829
otelConfigPath = path.Join(path.Dir(executablePath), otelConfigDirName)
2930

3031
if _, err := os.Stat(otelConfigPath); os.IsNotExist(err) {
31-
return fmt.Errorf("the directory in which the plugin binary is executed is missing necessary files, so please make sure the plugin was installed using \"spin plugins install otel\"")
32+
return fmt.Errorf("The directory in which the plugin binary is executed is missing necessary files, so please make sure the plugin was installed using \"spin plugins install otel\"")
33+
}
34+
35+
return nil
36+
}
37+
38+
// checkDocker checks whether Docker is installed and the Docker daemon is running
39+
func checkDocker() error {
40+
cmd := exec.Command("docker", "--version")
41+
if err := cmd.Run(); err != nil {
42+
return fmt.Errorf("Docker appears not to be installed, so please visit their install page and try again once installed: https://www.docker.com/products/docker-desktop")
43+
}
44+
45+
cmd = exec.Command("docker", "info")
46+
if err := cmd.Run(); err != nil {
47+
return fmt.Errorf("The Docker daemon appears not to be running. The command to start Docker depends on your operating system. For instructions, check the correct page under https://docs.docker.com/engine/install")
3248
}
3349

3450
return nil
3551
}
3652

3753
func Execute() {
3854
if err := setOtelConfigPath(); err != nil {
39-
fmt.Fprintln(os.Stderr, fmt.Errorf("error finding the otel-config directory: %w", err))
55+
fmt.Fprintln(os.Stderr, fmt.Errorf("Error finding the \"otel-config\" directory: %w", err))
4056
os.Exit(1)
4157
}
4258

4359
if err := rootCmd.Execute(); err != nil {
44-
fmt.Fprintln(os.Stderr, err)
4560
os.Exit(1)
4661
}
4762
}

cmd/setup.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@ var setUpCmd = &cobra.Command{
2121
}
2222

2323
func setUp() error {
24+
if err := checkDocker(); err != nil {
25+
return err
26+
}
27+
2428
composeFile := path.Join(otelConfigPath, "compose.yaml")
2529
if _, err := os.Stat(composeFile); os.IsNotExist(err) {
26-
return fmt.Errorf("the otel-config directory is missing the \"compose.yaml\" file, so please consider removing and re-installing the otel plugin")
30+
return fmt.Errorf("The \"otel-config\" directory is missing the \"compose.yaml\" file, so please consider removing and re-installing the otel plugin")
2731
}
2832

2933
cmd := exec.Command("docker", "compose", "-f", composeFile, "up", "-d")
@@ -36,6 +40,6 @@ func setUp() error {
3640
return err
3741
}
3842

39-
fmt.Println("The Spin OTel resources are now running. Be sure to run the `spin otel cleanup` command when you are finished using them.")
43+
fmt.Println("The Spin OTel resources are now running. Be sure to run the \"spin otel cleanup\" command when you are finished using them.")
4044
return nil
4145
}

cmd/up.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
var upCmd = &cobra.Command{
1212
Use: "up",
1313
Short: "Runs a Spin App with the default OTel environment variables.",
14-
Long: "Runs a Spin App with the default OTel environment variables. Any flags that work with the `spin up` command, will work with the `spin otel up` command: 'spin otel up -- --help'",
14+
Long: "Runs a Spin App with the default OTel environment variables. Any flags that work with the \"spin up\" command, will work with the \"spin otel up\" command: \"spin otel up -- --help\"",
1515
RunE: func(cmd *cobra.Command, args []string) error {
1616
if err := up(args); err != nil {
1717
return err
@@ -22,9 +22,13 @@ var upCmd = &cobra.Command{
2222
}
2323

2424
func up(args []string) error {
25+
if err := checkDocker(); err != nil {
26+
return err
27+
}
28+
2529
pathToSpin := os.Getenv("SPIN_BIN_PATH")
2630
if pathToSpin == "" {
27-
return fmt.Errorf("please ensure that you are running 'spin otel up', rather than calling the OTel plugin binary directly")
31+
return fmt.Errorf("Please ensure that you are running \"spin otel up\", rather than calling the OTel plugin binary directly")
2832
}
2933

3034
// Passing flags and args after the '--'

main.go

-23
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,9 @@
11
package main
22

33
import (
4-
"fmt"
5-
"os"
6-
"os/exec"
7-
84
"github.com/fermyon/otel-plugin/cmd"
95
)
106

117
func main() {
12-
if err := checkDependencies(); err != nil {
13-
fmt.Fprintln(os.Stderr, err)
14-
os.Exit(1)
15-
}
16-
178
cmd.Execute()
189
}
19-
20-
func checkDependencies() error {
21-
cmd := exec.Command("docker", "--version")
22-
if err := cmd.Run(); err != nil {
23-
return fmt.Errorf("docker appears not to be installed, so please visit their install page and try again once installed: https://www.docker.com/products/docker-desktop/")
24-
}
25-
26-
cmd = exec.Command("docker", "info")
27-
if err := cmd.Run(); err != nil {
28-
return fmt.Errorf("the docker daemon appears not to be running, so please start the daemon and try again")
29-
}
30-
31-
return nil
32-
}

0 commit comments

Comments
 (0)