Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion internal/cmds/inspect.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmds

import (
"context"
"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -78,8 +79,24 @@ func Inspect(cfg *config.Config) *cobra.Command {
}
return inspect.ValidateGroupBy(opts.GroupBy)
},
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, args []string) (runErr error) {
startTime := time.Now()

defer func() {
if runErr != nil {
msg := runErr.Error()
if len(msg) > 200 {
msg = msg[:200]
}
eventsClient := cfg.Events.Client(api.Client(context.Background(), cfg.Auth.TokenFromCache(context.Background()), cfg.OrgID))
eventsClient.Push(context.Background(), "infracost-error",
"error", msg,
"runSeconds", time.Since(startTime).Seconds(),
"outputFormat", "inspect",
)
}
}()

var data *format.Output
var err error

Expand Down
19 changes: 18 additions & 1 deletion internal/cmds/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ func ScanCmd(cfg *config.Config) *cobra.Command {
# Scan against a different organization's policies & prices
$ infracost scan --org acme`,
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, args []string) (runErr error) {
startTime := time.Now()

if len(args) > 0 {
in.Path = args[0]
}
Expand All @@ -189,6 +191,21 @@ func ScanCmd(cfg *config.Config) *cobra.Command {
outputFormat = "json"
}

defer func() {
if runErr != nil {
msg := runErr.Error()
if len(msg) > 200 {
msg = msg[:200]
}
eventsClient := cfg.Events.Client(api.Client(context.Background(), cfg.Auth.TokenFromCache(context.Background()), cfg.OrgID))
eventsClient.Push(context.Background(), "infracost-error",
"error", msg,
"runSeconds", time.Since(startTime).Seconds(),
"outputFormat", outputFormat,
)
}
}()

source, err := cfg.Auth.Token(cmd.Context())
if err != nil {
return fmt.Errorf("failed to log in: %w", err)
Expand Down
Loading