Skip to content

Commit 2f71b5f

Browse files
authored
Improve error messages and improve stacktraces (#2374)
1 parent fc08788 commit 2f71b5f

File tree

6 files changed

+29
-16
lines changed

6 files changed

+29
-16
lines changed

cli/cluster/errors.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ func ErrorFailedToConnectOperator(originalError error, envName string, operatorU
6363
msg += "\nif you have a cluster running:\n"
6464
msg += fmt.Sprintf(" → run `cortex cluster info --configure-env %s` to update your environment (include `--config <cluster.yaml>` if you have a cluster configuration file)\n", envName)
6565
msg += fmt.Sprintf(" → if you set `operator_load_balancer_scheme: internal` in your cluster configuration file, your CLI must run from within a VPC that has access to your cluster's VPC (see https://docs.cortex.dev/v/%s/)\n", consts.CortexVersionMinor)
66+
msg += fmt.Sprintf(" → confirm that the ip address of this machine falls within the CIDR ranges specified in `operator_load_balancer_cidr_whitelist`")
6667
}
6768

6869
return errors.WithStack(&errors.Error{

cli/cmd/cluster.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,14 +235,14 @@ var _clusterUpCmd = &cobra.Command{
235235
exit.Error(err)
236236
}
237237
if exitCode == nil || *exitCode != 0 {
238-
out = filterEKSCTLOutput(out)
238+
out = s.LastNChars(filterEKSCTLOutput(out), 8192) // get the last 8192 characters because that is the sentry message limit
239239
eksCluster, err := awsClient.EKSClusterOrNil(clusterConfig.ClusterName)
240240
if err != nil {
241241
helpStr := "\ndebugging tips (may or may not apply to this error):"
242242
helpStr += fmt.Sprintf("\n* if your cluster started spinning up but was unable to provision instances, additional error information may be found in the activity history of your cluster's autoscaling groups (select each autoscaling group and click the \"Activity\" or \"Activity History\" tab): https://console.aws.amazon.com/ec2/autoscaling/home?region=%s#AutoScalingGroups:", clusterConfig.Region)
243243
helpStr += "\n* if your cluster started spinning up, please run `cortex cluster down` to delete the cluster before trying to create this cluster again"
244244
fmt.Println(helpStr)
245-
exit.Error(ErrorClusterUp(out + helpStr))
245+
exit.Error(ErrorClusterUp(out))
246246
}
247247

248248
// the cluster never started spinning up
@@ -398,6 +398,8 @@ var _clusterConfigureCmd = &cobra.Command{
398398
exit.Error(err)
399399
}
400400
if exitCode == nil || *exitCode != 0 {
401+
out = s.LastNChars(out, 8192) // get the last 8192 characters because that is the sentry message limit
402+
401403
helpStr := "\ndebugging tips (may or may not apply to this error):"
402404
helpStr += fmt.Sprintf(
403405
"\n* if your cluster was unable to provision/remove/scale some nodegroups, additional error information may be found in the description of your cloudformation stack (https://console.aws.amazon.com/cloudformation/home?region=%s#/stacks)"+

pkg/operator/endpoints/errors.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,17 @@ func ErrorHeaderMissing(header string) error {
5353
})
5454
}
5555

56+
func ErrorAuthHeaderMissing(header, host, url string) error {
57+
return errors.WithStack(&errors.Error{
58+
Kind: ErrHeaderMissing,
59+
Message: fmt.Sprintf("missing %s header", header),
60+
Metadata: map[string]string{
61+
"host": host,
62+
"url": url,
63+
},
64+
})
65+
}
66+
5667
func ErrorHeaderMalformed(header string) error {
5768
return errors.WithStack(&errors.Error{
5869
Kind: ErrHeaderMalformed,

pkg/operator/endpoints/middleware.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func AWSAuthMiddleware(next http.Handler) http.Handler {
6464
authHeader := r.Header.Get(consts.AuthHeader)
6565

6666
if authHeader == "" {
67-
respondError(w, r, ErrorHeaderMissing(consts.AuthHeader))
67+
respondError(w, r, ErrorAuthHeaderMissing(consts.AuthHeader, r.Host, r.RequestURI))
6868
return
6969
}
7070

pkg/operator/resources/asyncapi/queue_metrics.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/aws/aws-sdk-go/aws"
2525
"github.com/aws/aws-sdk-go/service/sqs"
2626
"github.com/cortexlabs/cortex/pkg/config"
27+
"github.com/cortexlabs/cortex/pkg/lib/errors"
2728
"github.com/cortexlabs/cortex/pkg/types/userconfig"
2829
"github.com/prometheus/client_golang/prometheus"
2930
"github.com/prometheus/client_golang/prometheus/promauto"
@@ -74,20 +75,20 @@ func updateQueueLengthMetricsFn(apiName, queueURL string) func() error {
7475

7576
output, err := sqsClient.GetQueueAttributesWithContext(ctx, input)
7677
if err != nil {
77-
return err
78+
return errors.WithStack(err)
7879
}
7980

8081
visibleMessagesStr := output.Attributes["ApproximateNumberOfMessages"]
8182
invisibleMessagesStr := output.Attributes["ApproximateNumberOfMessagesNotVisible"]
8283

8384
visibleMessages, err := strconv.ParseFloat(*visibleMessagesStr, 64)
8485
if err != nil {
85-
return err
86+
return errors.WithStack(err)
8687
}
8788

8889
invisibleMessages, err := strconv.ParseFloat(*invisibleMessagesStr, 64)
8990
if err != nil {
90-
return err
91+
return errors.WithStack(err)
9192
}
9293

9394
activeGauge.WithLabelValues(apiName).Set(invisibleMessages)

python/client/cortex/client.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,29 @@
1515
import json
1616
import os
1717
import shutil
18-
import subprocess
19-
import sys
20-
import threading
2118
import time
2219
import yaml
23-
from pathlib import Path
24-
from typing import Optional, List, Dict, Any
20+
from typing import List, Dict, Any
2521

2622
from cortex import util
27-
from cortex.binary import run_cli, get_cli_path
23+
from cortex.binary import run_cli
2824
from cortex.telemetry import sentry_wrapper
2925

3026

3127
class Client:
3228
@sentry_wrapper
33-
def __init__(self, env: Dict):
29+
def __init__(self, env_config: Dict):
3430
"""
3531
A client to deploy and manage APIs in the specified environment.
32+
This constructor is not meant to be invoked directly.
33+
Use `cortex.client()` and `cortex.new_client()` to initialize a new cortex client.
3634
3735
Args:
38-
env: Environment config
36+
env_config: Environment config
3937
"""
4038

41-
self.env = env
42-
self.env_name = env["name"]
39+
self.env = env_config
40+
self.env_name = env_config["name"]
4341

4442
# CORTEX_VERSION_MINOR
4543
@sentry_wrapper

0 commit comments

Comments
 (0)