feat(doctor): report a key an env file sets twice, and let the editor resolve it - #1403
Merged
Conversation
… resolve it A site showed postgres on every surface while the application ran on SQLite, and nothing anywhere said why. Its env file set DATABASE_URL twice: lerd read the first, the framework read the last, and both were behaving correctly. Neither reading is wrong in general, which is why this reports rather than resolves. Symfony's dotenv parses into an array so a later assignment overwrites an earlier one and the last wins; Laravel loads through phpdotenv's immutable writer, which refuses to overwrite a name already set, so the first wins. lerd reads the first everywhere. A single rule cannot be right for both, and picking one silently is how a site ends up served from a database nobody chose. The doctor names the key, how many times it is set, the value lerd uses and the value at the end of the file, so the disagreement is visible instead of being something to work out from three surfaces contradicting each other. Only dotenv files are ambiguous this way: a PHP file's duplicate has one answer the language decides, and lerd reads those the way PHP runs them. The env editor shows the same conflict against the buffer, with each occurrence and its line, and keeping one drops the others. That leaves an ordinary unsaved change the user reviews and saves with the normal button, the way a staged missing key already works, so nothing is rewritten behind their back.
The first cut stacked a banner per duplicated key in the editor, which reads well for the one key that prompted it and badly for a file with several: the keys need not be related, and a project can carry a handful for the same reason it carries one. They collapse into a single banner now, saying how many keys are affected, and one modal lists them all: each key, each of its live occurrences with the line number and value, and a choice of which to keep. Nothing is preselected, because lerd cannot know which value the project meant and a default would read as a recommendation. Confirming drops the other occurrences from the editor buffer, bottom up so each removal leaves the earlier line numbers valid, and leaves an ordinary unsaved change to review and save with the normal button. The doctor offers the same resolver rather than repeating the values it found: its finding carries a fix that sends the user to the env tab with the modal already asked for, and the tab opens it once the file has loaded. It is the one fix key that resolves nothing by itself, which is right for a conflict only the project can settle.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A site showed postgres on every surface while the application ran on SQLite, and nothing anywhere said why. Its env file set DATABASE_URL twice: lerd read the first, the framework read the last, and both were behaving correctly.
Neither reading is wrong in general, which is why this reports rather than resolves. Symfony's dotenv parses into an array so a later assignment overwrites an earlier one and the last wins. Laravel loads through phpdotenv's immutable writer, which refuses to overwrite a name that is already set, so the first wins. lerd reads the first everywhere. A single rule cannot be right for both, and picking one silently is how a site ends up served from a database nobody chose.
The doctor names the key, how many times it is set, the value lerd uses and the value at the end of the file:
Only dotenv files are ambiguous this way. A PHP file's duplicate has one answer the language decides, a second define being ignored and a later assignment replacing an earlier one, and lerd reads those the way PHP runs them.
The env editor shows the same conflict against the buffer rather than against disk, so it tracks edits, listing each occurrence with its line number and value. Keeping one drops the others, which leaves an ordinary unsaved change the user reviews and saves with the normal button, the way a staged missing key already works. Nothing is rewritten behind their back.
Driven against a real Symfony site carrying the duplicate, and against five other real sites to confirm none of them gains a finding.
Closes #1390