X Tutup
Skip to content

Commit 8e64c14

Browse files
committed
Return errors in ask stubber instead of panicking
1 parent 62bd828 commit 8e64c14

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

pkg/prompt/stubber.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func InitAskStubber() (*AskStubber, func()) {
4141
message = pt.Message
4242
defaultValue = pt.Default
4343
default:
44-
panic(fmt.Sprintf("prompt type %T is not supported by the stubber", pt))
44+
return fmt.Errorf("prompt type %T is not supported by the stubber", pt)
4545
}
4646

4747
var stub *QuestionStub
@@ -53,12 +53,12 @@ func InitAskStubber() (*AskStubber, func()) {
5353
}
5454
}
5555
if stub == nil {
56-
panic(fmt.Sprintf("no prompt stub for %q", message))
56+
return fmt.Errorf("no prompt stub for %q", message)
5757
}
5858

5959
if len(stub.options) > 0 {
6060
if err := compareOptions(stub.options, options); err != nil {
61-
panic(fmt.Sprintf("options mismatch for %q: %v", message, err))
61+
return fmt.Errorf("stubbed options mismatch for %q: %v", message, err)
6262
}
6363
}
6464

@@ -73,7 +73,7 @@ func InitAskStubber() (*AskStubber, func()) {
7373
}
7474
}
7575
if foundIndex < 0 {
76-
panic(fmt.Sprintf("answer %q not found in options for %q: %v", stringValue, message, options))
76+
return fmt.Errorf("answer %q not found in options for %q: %v", stringValue, message, options)
7777
}
7878
userValue = core.OptionAnswer{
7979
Value: stringValue,

0 commit comments

Comments
 (0)
X Tutup