Skip to content

Commit 9e94e35

Browse files
committed
Add error checking to critical params
1 parent e6f67ef commit 9e94e35

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

cmd/submit.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,13 @@ func (ctx *submitContext) documents(exerciseDir string) ([]workspace.Document, e
276276
}
277277

278278
func (ctx *submitContext) writeFormFiles(writer *multipart.Writer, docs []workspace.Document) error {
279+
if writer == nil {
280+
return errors.New("writer is empty")
281+
}
282+
if len(docs) == 0 {
283+
return errors.New("docs is empty")
284+
}
285+
279286
for _, doc := range docs {
280287
file, err := os.Open(doc.Filepath())
281288
if err != nil {
@@ -299,6 +306,13 @@ func (ctx *submitContext) writeFormFiles(writer *multipart.Writer, docs []worksp
299306
}
300307

301308
func (ctx *submitContext) submitRequest(id string, writer *multipart.Writer, body *bytes.Buffer) error {
309+
if writer == nil {
310+
return errors.New("writer is empty")
311+
}
312+
if body.Len() == 0 {
313+
return errors.New("body is empty")
314+
}
315+
302316
client, err := api.NewClient(ctx.usrCfg.GetString("token"), ctx.usrCfg.GetString("apibaseurl"))
303317
if err != nil {
304318
return err

0 commit comments

Comments
 (0)