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

cmd: fix regression in auto-detect of Caddyfile #6362

Merged
merged 4 commits into from
Jun 2, 2024

Conversation

mohammed90
Copy link
Member

@mohammed90 mohammed90 commented Jun 2, 2024

Signed-off-by: Mohammed Al Sahaf <msaa1990@gmail.com>
@mohammed90 mohammed90 added the bug 🐞 Something isn't working label Jun 2, 2024
@mohammed90 mohammed90 added this to the v2.8.3 milestone Jun 2, 2024
cmd/main.go Outdated Show resolved Hide resolved
Co-authored-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
@francislavoie
Copy link
Member

Can we add more test coverage for this?

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.

Thanks for the quick patch. Some mostly unimportant thoughts...

cmd/main.go Outdated Show resolved Hide resolved
cmd/main.go Outdated Show resolved Hide resolved
wantErr: true,
},
{
name: "json is not caddyfile but not error",
Copy link
Member

Choose a reason for hiding this comment

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

This case is still confusing to me 😅 and I almost wonder if it should be an error.

Copy link
Member

Choose a reason for hiding this comment

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

We can duke it out later, but might be worth discussing at some point.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm using an error return as a signal of ambiguity. We consider .json a known extension, so it's not ambiguous. The determination is: .json is not ambiguous and isn't a Caddyfile.

Copy link
Member

Choose a reason for hiding this comment

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

I use files like Caddyfile.test2 kinda thing, it's not uncommon to have like Caddyfile.dev and Caddyfile.prod. I'm not sure I understand how those will behave from looking at the code (just woke up and still away from home 😅)

Copy link
Member Author

Choose a reason for hiding this comment

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

If you pass the --adpater, it will go through as Caddyfile. If this is common, I'd rather we strip the whole .caddyfile detection out.

Copy link
Member

Choose a reason for hiding this comment

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

I think it is common, and historically it has gone with the "starts with Caddyfile" rule. I think we only want to say it's ambiguous if there is a loaded adapter that matches the extension, not otherwise. I think it's fine if Caddyfile.yaml works if the yaml adapter isn't loaded. I realize that it's probably hard to test for though since we don't have any in Caddy itself. Maybe for testing, can make a dummy adapter?

Copy link
Member Author

@mohammed90 mohammed90 Jun 2, 2024

Choose a reason for hiding this comment

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

Then I think we should accept that users make silly mistakes such as passing --config Caddyfile.yaml without --adapter, or will do caddy run without specifying the --adapter which will cause the yaml file to be read as Caddyfile. It'll just fail silently (or loudly 🤷🏼‍♂️ ).

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.

Thank you!

I will merge this and tag a new release now.

@mholt mholt enabled auto-merge (squash) June 2, 2024 11:37
@mholt mholt merged commit 7088605 into master Jun 2, 2024
23 checks passed
@mholt mholt deleted the fix-config-file-detection-regrerssion branch June 2, 2024 11:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐞 Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error: ambiguous config file format; please specify adapter (use --adapter) since 2.8.2
5 participants