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

httpcaddyfile: Improve error on matcher declared outside site block #3431

Merged
merged 1 commit into from
May 20, 2020

Conversation

francislavoie
Copy link
Member

@francislavoie francislavoie commented May 20, 2020

We don't support defining matchers outside of site blocks. Some users try it, but get confusing error messaging because it still gets read as a site address. Instead, we can improve the error message in those cases because a site address starting with @ isn't valid anyways.

Consider this Caddyfile:

@foo {
	path /bar/*
}

localhost {
	respond "hello"
}

Before:

$ ./caddy adapt --config Caddyfile
adapt: Caddyfile:2: unrecognized directive: path

After:

$ ./caddy adapt --config Caddyfile
adapt: cannot define a matcher outside of a site block: '@foo'

@francislavoie francislavoie added this to the 2.1 milestone May 20, 2020
@francislavoie francislavoie requested a review from mholt May 20, 2020 00:27
Copy link
Member

@mholt mholt left a comment

Choose a reason for hiding this comment

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

I like the idea of a specialized error message, but this is the wrong implementation: it forbids any Caddyfile format from having keys that start with @ (imagine, for example, an email server Caddyfile, or a Twitter something-or-other Caddyfile). This change should be made within the httpcaddyfile package.

@mholt mholt added the under review 🧐 Review is pending before merging label May 20, 2020
@francislavoie francislavoie force-pushed the improve-matcher-error branch from a23b951 to 9b4fc52 Compare May 20, 2020 00:48
@francislavoie francislavoie changed the title caddyfile: Improved error message on matcher declared outside site block httpcaddyfile: Improve error on matcher declared outside site block May 20, 2020
@francislavoie
Copy link
Member Author

francislavoie commented May 20, 2020

Good point. Updated.

Doing it in httpcaddyfile means we lose information about the current line and filename we're on though, but no big deal.

@francislavoie francislavoie requested a review from mholt May 20, 2020 00:49
Copy link
Member

@mholt mholt left a comment

Choose a reason for hiding this comment

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

Cool, thanks!

@mholt mholt merged commit cc8fb48 into caddyserver:master May 20, 2020
@mholt mholt removed the under review 🧐 Review is pending before merging label May 20, 2020
@francislavoie francislavoie deleted the improve-matcher-error branch May 20, 2020 17:00
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