Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update login error message #4952

Merged
merged 4 commits into from
Sep 18, 2024
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
2 changes: 1 addition & 1 deletion src/bentoml/_internal/cloud/bentocloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ def pull_model(model_tag: Tag):
with response_ctx as response:
if response.status_code != 200:
raise BentoMLException(
f'Failed to download bento "{_tag}": {response.text}'
f'Failed to download bento "{_tag}", status_code: {response.status_code}'
)
total_size_in_bytes = int(response.headers.get("content-length", 0))
block_size = 1024 # 1 Kibibyte
Expand Down
2 changes: 1 addition & 1 deletion src/bentoml/_internal/cloud/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def get_context(self, context: t.Optional[str] = None) -> CloudClientContext:
if ctx.name == context:
return ctx
raise CloudRESTApiClientError(
f"BentoCloud API token for {context} cloud context is required.",
f"No cloud context {context} found",
aarnphm marked this conversation as resolved.
Show resolved Hide resolved
error_code=HTTPStatus.UNAUTHORIZED,
)

Expand Down
2 changes: 1 addition & 1 deletion src/bentoml_cli/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def login(endpoint: str, api_token: str) -> None: # type: ignore (not accessed)
encodedCallback = urllib.parse.quote(callback_server.callback_url)
authURL = f"{baseURL}?callback={encodedCallback}"
if Confirm.ask(
f"Please Enter Y or N to open [blue]{authURL}[/] in your browser..."
f"Please Enter Y to open [blue]{authURL}[/] in your browser..."
):
if webbrowser.open_new_tab(authURL):
rich.print(f"✅ Opened [blue]{authURL}[/] in your web browser.")
Expand Down
14 changes: 9 additions & 5 deletions src/bentoml_cli/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
def raise_deployment_config_error(err: BentoMLException, action: str) -> t.NoReturn:
if err.error_code == HTTPStatus.UNAUTHORIZED:
raise BentoMLException(
f"{err}\n* BentoCloud sign up: https://cloud.bentoml.com/\n"
"* Login with your API token: "
"https://docs.bentoml.com/en/latest/bentocloud/how-tos/manage-access-token.html"
f"{err}\n* BentoCloud API token is required for authorization. Run `bentoml cloud login` command to login"
) from None
raise BentoMLException(
f"Failed to {action} deployment due to invalid configuration: {err}"
Expand Down Expand Up @@ -609,7 +607,10 @@ def list_command( # type: ignore
output: t.Literal["json", "yaml", "table"],
) -> None:
"""List existing deployments on BentoCloud."""
d_list = Deployment.list(cluster=cluster, search=search)
try:
d_list = Deployment.list(cluster=cluster, search=search)
except BentoMLException as e:
raise_deployment_config_error(e, "list")
res: list[dict[str, t.Any]] = [d.to_dict() for d in d_list]
if output == "table":
table = Table(box=None, expand=True)
Expand Down Expand Up @@ -649,7 +650,10 @@ def list_instance_types( # type: ignore
output: t.Literal["json", "yaml", "table"],
) -> None:
"""List existing instance types in cluster on BentoCloud."""
d_list = Deployment.list_instance_types(cluster=cluster)
try:
d_list = Deployment.list_instance_types(cluster=cluster)
except BentoMLException as e:
xianml marked this conversation as resolved.
Show resolved Hide resolved
raise_deployment_config_error(e, "list_instance_types")
res: list[dict[str, t.Any]] = [d.to_dict() for d in d_list]
if output == "table":
table = Table(box=None, expand=True)
Expand Down
17 changes: 9 additions & 8 deletions src/bentoml_cli/secret.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ def list(
output: t.Literal["json", "yaml", "table"],
):
"""List all secrets on BentoCloud."""
secrets = Secret.list(search=search)
try:
secrets = Secret.list(search=search)
except BentoMLException as e:
xianml marked this conversation as resolved.
Show resolved Hide resolved
raise_secret_error(e, "list")
if output == "table":
table = Table(box=None, expand=True)
table.add_column("Secret", overflow="fold")
Expand Down Expand Up @@ -137,10 +140,8 @@ def parse_from_file_argument_callback(
def raise_secret_error(err: BentoMLException, action: str) -> t.NoReturn:
if err.error_code == HTTPStatus.UNAUTHORIZED:
raise BentoMLException(
f"{err}\n* BentoCloud sign up: https://cloud.bentoml.com/\n"
"* Login with your API token: "
"https://docs.bentoml.com/en/latest/bentocloud/how-tos/manage-access-token.html"
)
f"{err}\n* BentoCloud API token is required for authorization. Run `bentoml cloud login` command to login"
) from None
raise BentoMLException(f"Failed to {action} secret due to: {err}")


Expand Down Expand Up @@ -232,7 +233,7 @@ def create(
key_vals=key_vals,
)
rich.print(f"Secret [green]{secret.name}[/] created successfully")
except Exception as e:
except BentoMLException as e:
raise_secret_error(e, "create")


Expand All @@ -248,7 +249,7 @@ def delete(name: str):
try:
Secret.delete(name=name)
rich.print(f"Secret [green]{name}[/] deleted successfully")
except Exception as e:
except BentoMLException as e:
raise_secret_error(e, "delete")


Expand Down Expand Up @@ -335,5 +336,5 @@ def apply(
key_vals=key_vals,
)
rich.print(f"Secret [green]{secret.name}[/] applied successfully")
except Exception as e:
except BentoMLException as e:
raise_secret_error(e, "apply")
Loading