Skip to content

Fix a case where the GPU types from config could be nil#17

Merged
noorvir merged 2 commits intomasterfrom
unw-187
Jun 7, 2023
Merged

Fix a case where the GPU types from config could be nil#17
noorvir merged 2 commits intomasterfrom
unw-187

Conversation

@caldempsey
Copy link
Copy Markdown
Contributor

@caldempsey caldempsey commented Jun 2, 2023

This PR fixes a case where GPU types from config was an empty list of .unweave/config.toml did not contain any GPUs in node_types , by introducing an empty string as the static default for the CLI to go by. API call result:

  • Resolves UNW-187

image

@caldempsey caldempsey requested a review from noorvir June 4, 2023 20:57
var err error
gpuTypesFromConfig, err := gpuTypesFromConfig()
if err != nil {
ui.Errorf(err.Error())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This again exposes the internal error below. i.e. the user doesn't know what GPU type config should be provided or default, never nil means. We probably don't want to handle an error here and instead do it in the gpuTypesFromConfig function.

We will eventually need to refactor the error handling. A good convention might be to nevel os.Exit or print ui.* from a package that is not cmd. i.e. the cmd package handles all user interface things while sub return meaningful errors.

For now, let's just fix this error to not expose internal semantics.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I would probably lean towards doing a combination of this and using a function to handle errors on the CLI that only prints errors that are intended to be directed at the user.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think we need to hide the error handling behind too many functions. It makes code harder to read. The calling function has context of what the error might be (eg. Invalid GPU type) and is therefore the best place to print an error to the user. Redirecting to another function will result in more parsing of what the actual error was.

We can adopt a simple convention that anytime we make a request to a function that's not in the cmd package, we handle the result error on the spot.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated with this approach

@caldempsey caldempsey requested a review from noorvir June 7, 2023 09:48
@noorvir noorvir changed the title [UNW-187] Fix a case where the GPU types from config could be nil Fix a case where the GPU types from config could be nil Jun 7, 2023
@noorvir noorvir merged commit 938ba72 into master Jun 7, 2023
@noorvir noorvir deleted the unw-187 branch June 7, 2023 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants