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

Run_script echo output to console, and capture errors from script #3277

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
13 changes: 9 additions & 4 deletions bottles/backend/managers/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,18 @@ def __step_run_script(config: BottleConfig, step: dict):
return False

logging.info(f"Executing installer script…")
subprocess.Popen(
result = subprocess.run(
f"bash -c '{script}'",
shell=True,
cwd=ManagerUtils.get_bottle_path(config),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
).communicate()
capture_output=True,
)
logging.info(f"Output: \n{result.stdout.decode()}\n")
if result.returncode != 0:
Copy link
Member

@mirkobrombin mirkobrombin Feb 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change this to return result.returncode == 0 this will return True if the condition meet and False otherwise. If you look at how the install function executes the installer' steps, it checks if one of them returns False

if not self.__perform_steps(_config, steps):
return Result(
False, data={"message": "Installer is not well configured."}
)
and then return a proper Result object according to that.

Currently, there is no easy way to show a message to the user graphically. It could be possible by making each step returning a tuple (boolean, message) and have the install function append that message to the Result object, then updating the installer view in the frontend to use that message if available

def __install(self, *_args):
self.set_deletable(False)
self.stack.set_visible_child_name("page_install")
@GtkUtils.run_in_main_loop
def set_status(result, error=False):
if result.ok:
return self.__installed()
_err = result.data.get("message", _("Installer failed with unknown error"))
self.__error(_err)
self.set_steps(self.manager.installer_manager.count_steps(self.installer))
RunAsync(
task_func=self.manager.installer_manager.install,
callback=set_status,
config=self.config,
installer=self.installer,
step_fn=self.next_step,
local_resources=self.__final_resources,
)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding the line return result.returncode == 0 results in a known failure (exit 1) in the script not even putting a warning in the Console, and just continuing with the rest of the manifest steps.

Same goes for adding
return False
or

      return Result( 
         False, data={"message": "Installer is not well configured."} 
     ) 

Bottles just continues on with the rest of the manifest regardless of the failure

It looks like there is something missing to handle the return at this point, as it continues regardless of any state returned

# an error happened!
err_msg = "Status: FAIL \nError: %s\nCode: %s" % (result.stderr.decode(), result.returncode)
logging.error(err_msg)
# raise Exception(err_msg) #Raise blocking error
logging.info(f"Finished executing installer script.")

@staticmethod
Expand Down