caddy.go: Check whether @id is unique#7002
caddy.go: Check whether @id is unique#7002Chise1 wants to merge 2 commits intocaddyserver:masterfrom
Conversation
caddy.go
Outdated
| err2 := rollbackRawCfg() | ||
| if err2 != nil { | ||
| err = errors.Join(err, err2) | ||
| } |
There was a problem hiding this comment.
Trying to parse the old config here without checking the length of rawCfgJSON isn't a recommended approach. Additionally, this is a potential duplicate of the call in Ln246
There was a problem hiding this comment.
May I ask if there are any areas in this pr that need to be modified and if it can be merged?
caddy.go
Outdated
| err := json.Unmarshal(rawCfgJSON, &oldCfg) | ||
| rawCfg[rawConfigKey] = oldCfg |
There was a problem hiding this comment.
obs: Potential nil assignment to rawCfg. Check for error before assigning to the map
|
I added length detection and fixed a stupid problem. From the perspective of code analysis, "err" will not be repeated. Changes of rewrite, involves nginx-adapter-case |
Please keep the PR topical and focused. Split these changes into a separate PR. |
|
I have deleted the irrelevant pr |
|
I feel like a better approach would be to check the ID as it's being read in and we're creating the mapping of IDs to their full config paths. If we return an error the rest should be handled automatically (no need to roll back, etc) |
If we do as you said, the content that needs to be modified is rather complicated. This is beyond my ability. I'm worried that the modification will introduce bugs. |
|
add one test. |
|
Since this fell inactive, I took it upon myself to try and reimplement this. The tests were good, thanks! It was a good starting point. I pointed Gemini 3.1 Pro + Github Copilot at this to take a shot at doing it more cleanly. I rebased and pushed my version on top. The result is quite a lot simpler. The new functions weren't really necessary. |
Fixes: #6991
Check whether @id is unique.If it is not unique,rollback caddy config json.
I'm not sure if it can work properly under caddyfile.