Skip to content

Commit

Permalink
fix: panic if daemon command is invalid (#788)
Browse files Browse the repository at this point in the history
* fix: panic if daemon command is invalid

Signed-off-by: Keming <kemingyang@tensorchord.ai>

* Update pkg/lang/frontend/starlark/runtime/runtime.go

Co-authored-by: Ce Gao <ce.gao@outlook.com>
Signed-off-by: Keming <kemingy94@gmail.com>

* fix errorf

Signed-off-by: Keming <kemingyang@tensorchord.ai>

* fix import but not used

Signed-off-by: Keming <kemingyang@tensorchord.ai>

Signed-off-by: Keming <kemingyang@tensorchord.ai>
Signed-off-by: Keming <kemingy94@gmail.com>
Co-authored-by: Ce Gao <ce.gao@outlook.com>
  • Loading branch information
kemingy and gaocegege authored Aug 17, 2022
1 parent 4d48767 commit 7d293d7
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions pkg/lang/frontend/starlark/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
package runtime

import (
"errors"
"fmt"

"github.com/cockroachdb/errors"
"github.com/sirupsen/logrus"
"go.starlark.net/starlark"
"go.starlark.net/starlarkstruct"
Expand Down Expand Up @@ -51,7 +49,7 @@ func ruleFuncCommand(thread *starlark.Thread, _ *starlark.Builtin,
commandsMap := make(map[string]string)
for _, tuple := range commands.Items() {
if len(tuple) != 2 {
return nil, fmt.Errorf("invalid command in %s", ruleCommand)
return nil, errors.Newf("invalid command in %s", ruleCommand)
}

commandsMap[tuple[0].(starlark.String).GoString()] =
Expand All @@ -78,8 +76,7 @@ func ruleFuncDaemon(thread *starlark.Thread, _ *starlark.Builtin,
for i := 0; i < commands.Len(); i++ {
args, ok := commands.Index(i).(*starlark.List)
if !ok {
logger.Warnf("cannot parse %s into a list of string", commands.Index(i).String())
continue
return nil, errors.Newf("invalid daemon commands (%s)", commands.Index(i).String())
}
argList := []string{}
for j := 0; j < args.Len(); j++ {
Expand Down Expand Up @@ -132,7 +129,7 @@ func ruleFuncEnviron(thread *starlark.Thread, _ *starlark.Builtin,
envMap := make(map[string]string)
for _, tuple := range env.Items() {
if len(tuple) != 2 {
return nil, fmt.Errorf("invalid env (%s)", tuple.String())
return nil, errors.Newf("invalid env (%s)", tuple.String())
}

envMap[tuple[0].(starlark.String).GoString()] = tuple[1].(starlark.String).GoString()
Expand Down

0 comments on commit 7d293d7

Please sign in to comment.