-
Notifications
You must be signed in to change notification settings - Fork 301
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
Improve error message for ImageSpec #2498
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,6 +107,8 @@ def is_container(self) -> bool: | |
def exist(self) -> bool: | ||
""" | ||
Check if the image exists in the registry. | ||
Return True if the image exists in the registry, False otherwise. | ||
Return None if failed to check if the image exists due to the permission issue or other reasons. | ||
""" | ||
import docker | ||
from docker.errors import APIError, ImageNotFound | ||
|
@@ -121,7 +123,10 @@ def exist(self) -> bool: | |
except APIError as e: | ||
if e.response.status_code == 404: | ||
return False | ||
return True | ||
|
||
click.secho(f"Failed to check if the image exists with error:\n {e}", fg="red") | ||
click.secho(f"Flytekit assumes the image {self.image_name()} already exists.", fg="blue") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
return None | ||
except ImageNotFound: | ||
return False | ||
except Exception as e: | ||
|
@@ -153,9 +158,9 @@ def exist(self) -> bool: | |
f" pip install --upgrade docker" | ||
) | ||
|
||
click.secho(f"Failed to check if the image exists with error : {e}", fg="red") | ||
click.secho("Flytekit assumes that the image already exists.", fg="blue") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we ensure we handle runtime error nicely in the clean exception in pyflyte There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated |
||
return True | ||
click.secho(f"Failed to check if the image exists with error:\n {e}", fg="red") | ||
click.secho(f"Flytekit assumes the image {self.image_name()} already exists.", fg="blue") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this print statement belongs in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That makes sense, I updated it, thanks! |
||
return None | ||
|
||
def __hash__(self): | ||
return hash(asdict(self).__str__()) | ||
|
@@ -240,14 +245,17 @@ def should_build(self, image_spec: ImageSpec) -> bool: | |
True if the image should be built, otherwise it returns False. | ||
""" | ||
img_name = image_spec.image_name() | ||
if not image_spec.exist(): | ||
exist = image_spec.exist() | ||
if exist is False: | ||
click.secho(f"Image {img_name} not found. building...", fg="blue") | ||
return True | ||
|
||
if image_spec._is_force_push: | ||
click.secho(f"Image {img_name} found but overwriting existing image.", fg="blue") | ||
click.secho(f"Overwriting existing image {img_name}.", fg="blue") | ||
return True | ||
|
||
click.secho(f"Image {img_name} found. Skip building.", fg="blue") | ||
if exist is True: | ||
click.secho(f"Image {img_name} found. Skip building.", fg="blue") | ||
return False | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,13 @@ | |
import pathlib | ||
import shutil | ||
import subprocess | ||
from dataclasses import asdict | ||
from importlib import metadata | ||
|
||
import click | ||
from packaging.version import Version | ||
from rich import print | ||
from rich.pretty import Pretty | ||
|
||
from flytekit.configuration import DefaultImages | ||
from flytekit.core import context_manager | ||
|
@@ -34,7 +37,16 @@ def build_image(self, image_spec: ImageSpec): | |
else: | ||
build_command += f" --tag {image_spec.image_name()}" | ||
envd_context_switch(image_spec.registry) | ||
execute_command(build_command) | ||
try: | ||
execute_command(build_command) | ||
except Exception as e: | ||
click.secho("❌ Failed to build image spec:", fg="red") | ||
print( | ||
Pretty( | ||
asdict(image_spec, dict_factory=lambda x: {k: v for (k, v) in x if v is not None}), indent_size=2 | ||
) | ||
) | ||
raise e from None | ||
|
||
|
||
def envd_context_switch(registry: str): | ||
|
@@ -68,7 +80,7 @@ def execute_command(command: str): | |
|
||
if p.returncode != 0: | ||
_, stderr = p.communicate() | ||
raise Exception(f"failed to run command {command} with error {stderr}") | ||
raise Exception(f"failed to run command {command} with error:\n {stderr.decode()}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change this to raise assertionerror There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated |
||
|
||
return result | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That Python typing for
exist
needs to be updated to includeNone
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated