Skip to content

fix: fail !env substitution when the named variable is missing (fixes #63) - #67

Merged
Manrich121 merged 2 commits into
powersync-ja:mainfrom
cpruijsen:fix/issue-63
Oct 26, 2026
Merged

Manrich121 merged 2 commits into
powersync-ja:mainfrom
cpruijsen:fix/issue-63

Conversation

@cpruijsen

Copy link
Copy Markdown
Contributor

Summary

!env already recorded a parse error that named a missing variable, but parseYamlFile ignored doc.errors and returned the variable name as the value. validate / deploy then treated uri: PS_DATABASE_URI as a connection string, and Cloud reported PSYNC_S1109 (protocol must be postgresql, got undefined). Parse now fails with that existing message so the missing variable is named, and --validate-only=connections no longer swallows the failure.

The reporter reproduced the Cloud protocol error on #63. Docs and README only describe process environment variables, not .env files.

Decision

  • Chose: Surface the existing !env parse error (name the missing variable). Do not auto-load .env / .env.local.
  • Alternative: Load .env then .env.local from the working directory (without overriding exported variables).
  • Why: The misleading error is a dropped parse failure, not missing dotenv. Auto-loading files is a new lookup policy this repo has never documented.
  • Happy to switch to dotenv loading if that is preferred.

ensureServiceTypeMatches only reads _type, so it uses parseYamlDocumentPreserveTags and does not require template !env placeholders to be set (same idea as the docker plugin when merging snippets).

Testing

  • Unit: parseYamlFile throws naming PS_DATABASE_URI when unset, and still substitutes when set.
  • powersync validate --validate-only=connections fails with that name and does not call testConnection.
  • powersync link self-hosted still works when service.yaml has unresolved !env URIs.

Closes #63

@CLAassistant

CLAassistant commented Sep 11, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

LucDeCaf
LucDeCaf previously approved these changes Sep 17, 2026

@LucDeCaf LucDeCaf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the contribution! Tested this on my side and it looks good, just a few small observations.
Also, don't forget to sign the CLA. :)

Comment thread cli/test/commands/validate.test.ts Resolved
Comment thread packages/cli-core/src/utils/yaml.ts Resolved
@cpruijsen

Copy link
Copy Markdown
Contributor Author

Signed the CLA. I also reworded the parseYamlFile docblock: it throws on any YAML parse error, including failed !env substitution.

@Manrich121
Manrich121 merged commit 8f72ea3 into powersync-ja:main Oct 26, 2026
1 check passed
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.

!env only resolves from exported variables; .env / .env.local are ignored and the error hides the cause

4 participants