Skip to content

Commit 2d2db65

Browse files
committed
Stop returning empty string
1 parent d1598f4 commit 2d2db65

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

schema/schema.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@ import (
1616
"gopkg.in/yaml.v2"
1717
)
1818

19-
// Finds the path to the schema file (preferring JSON), or empty string if neither exists
20-
func findSchemaPath() string {
19+
// Finds the path to the schema file (preferring JSON), or returns an error if neither exists
20+
func findSchemaPath() (string, error) {
2121
if _, err := os.Stat("testtrack/schema.json"); err == nil {
22-
return "testtrack/schema.json"
22+
return "testtrack/schema.json", nil
2323
}
2424
if _, err := os.Stat("testtrack/schema.yml"); err == nil {
25-
return "testtrack/schema.yml"
25+
return "testtrack/schema.yml", nil
2626
}
27-
return ""
27+
return "", errors.New("testtrack/schema.{json,yml} does not exist. Are you in your app root dir? If so, call testtrack init_project first")
2828
}
2929

3030
// Read a schema from disk or generate one
3131
func Read() (*serializers.Schema, error) {
32-
schemaPath := findSchemaPath()
33-
if schemaPath == "" {
32+
schemaPath, err := findSchemaPath()
33+
if err != nil {
3434
return Generate()
3535
}
3636
schemaBytes, err := os.ReadFile(schemaPath)
@@ -81,9 +81,9 @@ func Write(schema *serializers.Schema) error {
8181

8282
// Link a schema to the user's home dir
8383
func Link(force bool) error {
84-
schemaPath := findSchemaPath()
85-
if schemaPath == "" {
86-
return errors.New("testtrack/schema.{json,yml} does not exist. Are you in your app root dir? If so, call testtrack init_project first")
84+
schemaPath, err := findSchemaPath()
85+
if err != nil {
86+
return err
8787
}
8888
dir, err := os.Getwd()
8989
if err != nil {

0 commit comments

Comments
 (0)