@@ -16,6 +16,7 @@ import (
1616 "strings"
1717
1818 "github.com/gatewayd-io/gatewayd/config"
19+ gerr "github.com/gatewayd-io/gatewayd/errors"
1920 "github.com/google/go-github/v53/github"
2021 jsonSchemaGenerator "github.com/invopop/jsonschema"
2122 "github.com/knadh/koanf"
@@ -92,9 +93,7 @@ func generateConfig(
9293 cmd .Printf ("Config file '%s' was %s successfully." , configFile , verb )
9394}
9495
95- func lintConfig (cmd * cobra.Command , fileType configFileType , configFile string ) {
96- logger := log .New (cmd .OutOrStdout (), "" , 0 )
97-
96+ func lintConfig (fileType configFileType , configFile string ) error {
9897 // Load the config file and check it for errors.
9998 var conf * config.Config
10099 switch fileType {
@@ -109,7 +108,7 @@ func lintConfig(cmd *cobra.Command, fileType configFileType, configFile string)
109108 conf .LoadPluginConfigFile (context .TODO ())
110109 conf .UnmarshalPluginConfig (context .TODO ())
111110 default :
112- logger . Fatal ( "Invalid config file type" )
111+ return gerr . ErrLintingFailed
113112 }
114113
115114 // Marshal the config to JSON.
@@ -121,17 +120,17 @@ func lintConfig(cmd *cobra.Command, fileType configFileType, configFile string)
121120 case Plugins :
122121 jsonData , err = conf .PluginKoanf .Marshal (koanfJson .Parser ())
123122 default :
124- logger . Fatal ( "Invalid config file type" )
123+ return gerr . ErrLintingFailed
125124 }
126125 if err != nil {
127- logger . Fatalf ( "Error marshalling %s config to JSON: %s \n " , string ( fileType ), err )
126+ return gerr . ErrLintingFailed . Wrap ( err )
128127 }
129128
130129 // Unmarshal the JSON data into a map.
131130 var jsonBytes map [string ]interface {}
132131 err = json .Unmarshal (jsonData , & jsonBytes )
133132 if err != nil {
134- logger . Fatal ( "Error unmarshalling schema to JSON: \n " , err )
133+ return gerr . ErrLintingFailed . Wrap ( err )
135134 }
136135
137136 // Generate a JSON schema from the config struct.
@@ -142,28 +141,28 @@ func lintConfig(cmd *cobra.Command, fileType configFileType, configFile string)
142141 case Plugins :
143142 generatedSchema = jsonSchemaGenerator .Reflect (& config.PluginConfig {})
144143 default :
145- logger . Fatal ( "Invalid config file type" )
144+ return gerr . ErrLintingFailed
146145 }
147146
148147 // Marshal the schema to JSON.
149148 schemaBytes , err := json .Marshal (generatedSchema )
150149 if err != nil {
151- logger . Fatal ( "Error marshalling schema to JSON: \n " , err )
150+ return gerr . ErrLintingFailed . Wrap ( err )
152151 }
153152
154153 // Compile the schema for validation.
155154 schema , err := jsonSchemaV5 .CompileString ("" , string (schemaBytes ))
156155 if err != nil {
157- logger . Fatal ( "Error compiling schema: \n " , err )
156+ return gerr . ErrLintingFailed . Wrap ( err )
158157 }
159158
160159 // Validate the config against the schema.
161160 err = schema .Validate (jsonBytes )
162161 if err != nil {
163- logger . Fatalf ( "Error validating %s config: %s \n " , string ( fileType ), err )
162+ return gerr . ErrLintingFailed . Wrap ( err )
164163 }
165164
166- cmd . Printf ( "%s config is valid \n " , fileType )
165+ return nil
167166}
168167
169168func listPlugins (cmd * cobra.Command , pluginConfigFile string , onlyEnabled bool ) {
0 commit comments