Page MenuHomePhabricator

[builds-cli] give a nicer message for builds that are not found
Closed, ResolvedPublic

Description

Currently we show a dump instead of just "Build not found" message.

tools.wm-lol@tools-sgebastion-10:~$ toolforge build logs wm-lol-buildpacks-pipelinerun-h8fvnnsoteu
Traceback (most recent call last):
  File "/usr/bin/toolforge", line 8, in <module>
    sys.exit(main())
  File "/usr/lib/python3/dist-packages/toolforge_cli/cli.py", line 809, in main
    toolforge()
  File "/usr/lib/python3/dist-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3/dist-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python3/dist-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python3/dist-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3/dist-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/toolforge_cli/cli.py", line 440, in wrapper
    return func(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/toolforge_cli/cli.py", line 577, in build_logs
    logs = builds_client.get(f"/build/{run_name}/logs")
  File "/usr/lib/python3/dist-packages/toolforge_weld/api_client.py", line 52, in get
    r.raise_for_status()
  File "/usr/lib/python3/dist-packages/requests/models.py", line 940, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://api.svc.tools.eqiad1.wikimedia.cloud:30003/builds/v1//build/wm-lol-buildpacks-pipelinerun-h8fvnnsoteu/logs

This task is to change the cli to show a nicer message (as the reply is actually expected).

Event Timeline

dcaro triaged this task as High priority.May 17 2023, 4:20 PM
dcaro created this task.
Raymond_Ndibe changed the task status from Open to In Progress.May 29 2023, 11:31 PM

@dcaro the patch for T337903 already did something about this issue, but I was wondering if we'd sometime in the future attempt to build a system that sort of attempts to infer different errors and try to reword them to be maybe more explanatory. For example with the recent merge, trying to reproduce the scenario described in this issue with write only

Not Found for url: https://api.svc.tools.eqiad1.wikimedia.cloud:30003/builds/v1//build/wm-lol-buildpacks-pipelinerun-h8fvnnsoteu/logs

But I wonder if this is enough. Do you think there is a need have a system that can for example read the above error and reword it like

log for build wm-lol-buildpacks-pipelinerun-h8fvnnsoteu not found

But to get something like the above means having a way to handle all possible errors

@dcaro the patch for T337903 already did something about this issue, but I was wondering if we'd sometime in the future attempt to build a system that sort of attempts to infer different errors and try to reword them to be maybe more explanatory. For example with the recent merge, trying to reproduce the scenario described in this issue with write only

Not Found for url: https://api.svc.tools.eqiad1.wikimedia.cloud:30003/builds/v1//build/wm-lol-buildpacks-pipelinerun-h8fvnnsoteu/logs

But I wonder if this is enough. Do you think there is a need have a system that can for example read the above error and reword it like

log for build wm-lol-buildpacks-pipelinerun-h8fvnnsoteu not found

But to get something like the above means having a way to handle all possible errors

Yep, that's why generic errors might be misleading.

I think we should handle the most common cases (404 when specifying a build, etc.) and keep the "generic" as a fallback.

For example on that error, it would be better to reply with something like:

Build wm-lol-buildpacks-pipelinerun-h8fvnnsoteu not found

as that's the main reason why the logs endpoint would not be found (except if the api url configuration is bad or similar).

for this logs endpoint, for example, are there any other reason(s) 404 Client Error can be raised? I'm a bit weary of giving all incidence of 404 or say 500 HTTP error the same string explanation. It's tempting to try and see what the error message itself says. I guess my question can be better phrased as: Do we prefer to have these very specific error messages at the risk of mislabeling/misreporting some errors?

for this logs endpoint, for example, are there any other reason(s) 404 Client Error can be raised? I'm a bit weary of giving all incidence of 404 or say 500 HTTP error the same string explanation. It's tempting to try and see what the error message itself says. I guess my question can be better phrased as: Do we prefer to have these very specific error messages at the risk of mislabeling/misreporting some errors?

Currently there's 3 cases that we explicitly return 404:

  • If we did not find any pipelineruns matching the build id
  • If we found more than one pipeline run matching that id
  • If we failed to list any pipelineruns (k8s returning an error when doing a pipelinerun list)

Using a generated client would solve partially these issues as it would automatically parse the return values and return the right content, but as we are rewriting it in python I think that a safe strategy would be quite similar to what we were doing before:

  • Try to parse the content of the error as {"message": "somestring"}
    • If it worked, print only the message in a nice way (that is for errors we explicitly handle)
    • If it did not work, print the generic 404 error (this is for errors we don't handle, ex. if the url is malformed)