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

introduce inline templates for Macros #198

Merged
merged 1 commit into from
Jun 7, 2022
Merged

introduce inline templates for Macros #198

merged 1 commit into from
Jun 7, 2022

Conversation

Skeeve
Copy link
Contributor

@Skeeve Skeeve commented Jun 1, 2022

Templates in macros have to be either predefined ones (ac:…) or be defined in additional files.

With this PR one can use inline templates.

@Skeeve
Copy link
Contributor Author

Skeeve commented Jun 2, 2022

Noticed a bug

@Skeeve Skeeve closed this Jun 2, 2022
@Skeeve
Copy link
Contributor Author

Skeeve commented Jun 2, 2022

Not a bug, but me not understanding the levels of parsing.

@Skeeve Skeeve reopened this Jun 2, 2022
err,
"unable to unmarshal macros config template",
)
return nil
Copy link
Owner

Choose a reason for hiding this comment

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

should not we return the error here and below? karma.Format only adds a context-like message to an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I copied the error handing from the error handling already present there. You must know: I'm just a go-beginner and mostly learn by looking at other's code. So I assumed the error handling here

if err != nil {
err = karma.Format(err, "unable to load template")
return nil
}
is correct.

Copy link
Owner

Choose a reason for hiding this comment

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

Ah, you are actually right.

)
return nil
}
body, _ := cfg[template[1:]].(string)
Copy link
Owner

Choose a reason for hiding this comment

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

Will it always (like in 100% cases) go well? It doesn't feel too safe actually. Let's check that there is such a field in cfg first with comma-ok pattern?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As far as I understand, yes.

template is a string of at least 1 character, which will be '#' due to https://github.com/Skeeve/mark/blob/b7a30d6cf4e3fe0984cea44b4101e512b247fdfb/pkg/mark/macro/macro.go#L137

Also body will either be the inline macro's content or an empty string as, as far as I know, in case of a not-present map element, the result will be the empty string here:

https://github.com/Skeeve/mark/blob/b7a30d6cf4e3fe0984cea44b4101e512b247fdfb/pkg/mark/macro/macro.go#L148

So while it might produce unexpected results, it shouldn't crash.

But yes… An appropriate error message might be more helpful.

@kovetskiy kovetskiy merged commit 9ec7728 into kovetskiy:master Jun 7, 2022
@Skeeve Skeeve deleted the feature/inline_templates branch June 7, 2022 04:46
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