Skip to content

Template should not be evaluated in case of errored API responses #4255

@mislav

Description

@mislav

hi, I'm running some API commands by passing a template. When I pass an invalid value to GitHub's API, then the underlying API command fails and I get a template error.

For example:

> gh api --preview inertia "orgs/org-that-does-not-exist/projects" --template="{{range .}}{{.name}}{{end}}"
template: :1:13: executing "" at <.name>: can't evaluate field name in type interface {}

How would I do error handling in this case? As I'm using this command as part of my extension (see https://github.com/rethab/gh-project) I'd like the user not to see the template error message, but instead show the error message from GitHub's API.

In other words, the template should only be evaluated if the underlying API call was successful. Is that possible?

Originally posted by @rethab in #4254

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingpriority-2Affects more than a few users but doesn't prevent core functions

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions