Skip to content

Commit

Permalink
Errors in async init are not reported in interactive client if a quer…
Browse files Browse the repository at this point in the history
…y is entered before init is complete. Closes #843
  • Loading branch information
kaidaguerre authored Sep 3, 2021
1 parent 58f4b07 commit 1f0ae2b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 32 deletions.
11 changes: 4 additions & 7 deletions interactive/interactive_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,7 @@ func (c *InteractiveClient) executor(line string) {
query, err := c.getQuery(line)
if query == "" {
if err != nil {
if !utils.IsCancelledError(err) {
utils.ShowError(err)
}
// restart the prompt
c.restartInteractiveSession()
utils.ShowError(utils.HandleCancelError(err))
}
return
}
Expand Down Expand Up @@ -381,7 +377,6 @@ func (c *InteractiveClient) getQuery(line string) (string, error) {
// if it failed, report error and quit
close(initDoneChan)
display.StopSpinner(sp)
utils.ShowError(utils.HandleCancelError(err))
return "", err
}
close(initDoneChan)
Expand All @@ -397,7 +392,9 @@ func (c *InteractiveClient) getQuery(line string) (string, error) {
// in case of a named query call with params, parse the where clause
query, err := c.workspace().ResolveQueryAndArgs(queryString)
if err != nil {
return "", err
// if we fail to resolve, show error but do not return it - we want to stay in the prompt
utils.ShowError(err)
return "", nil
}
isNamedQuery := query != queryString

Expand Down
3 changes: 2 additions & 1 deletion interactive/interactive_client_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ func (c *InteractiveClient) waitForInitData(ctx context.Context) error {
return ctx.Err()
case <-ticker.C:
if c.isInitialised() {
return nil
// if there was an error in initialisation, return it
return c.initData.Result.Error
}
case <-time.After(initTimeout):
return fmt.Errorf("timed out waiting for initialisation to complete")
Expand Down
28 changes: 4 additions & 24 deletions steampipeconfig/test_data/demo/query_param_demo2/query.sp
Original file line number Diff line number Diff line change
@@ -1,29 +1,9 @@
query "expired_access_keys" {
query "bad_query" {
sql = <<-EOT
select
akas ->> 0 as resource,
case
when create_date > NOW() - ($1 || ' days')::interval then 'ok'
else 'alarm'
end as status,
access_key_id || 'for user ' || user_name || ' is ' || age(create_date) || ' old.' as reason,
region,
account_id
from
aws_iam_access_key
this is invalid
EOT
param "max_days" {
description = "The maximum number of days a key is allowed to exist after it is created."
default = 90
}
}

control "expired_access_keys" {
title = "Expired IAM Access Keys"
query = query.expired_access_keys
args = {
"max_days" = 365
param "tag_keys" {
default = "true"
}
}

0 comments on commit 1f0ae2b

Please sign in to comment.