Skip to content

ref(options): backport sentry OptionsResolver from 5.x#2151

Open
Litarnus wants to merge 1 commit into
masterfrom
backport-options-resolver
Open

ref(options): backport sentry OptionsResolver from 5.x#2151
Litarnus wants to merge 1 commit into
masterfrom
backport-options-resolver

Conversation

@Litarnus

@Litarnus Litarnus commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

A while ago we introduced a custom OptionsResolver that works similar to the Symfony OptionsResolver but allows us to remove it as dependency and making the PHP SDK easier to install.

The new data collection configuration structure introduced nested configuration, which increased the necessity of the options resolver in the current major branch.

This PR replaces the symfony options resolver with the custom one but does not alter the required dependencies.

Comment thread src/Options.php
Comment thread src/OptionsResolver.php
Comment on lines +49 to +59

if (!$validation[0]) {
// Since defaults are used as fallback values if passed options are invalid, we want to
// get hard errors here to make sure we have something to fall back to.
throw new \InvalidArgumentException(\sprintf('Invalid default for option "%s"', $option));
}

$processed[$option] = $validation[1];
}

$this->defaults = $processed;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: An invalid SENTRY_DSN environment variable causes a generic InvalidArgumentException during SDK initialization, without explaining why the DSN is invalid.
Severity: HIGH

Suggested Fix

Modify the validation logic to catch the specific exception from Dsn::createFromString() and re-throw it or include its message in the InvalidArgumentException. This will provide developers with actionable information about why the DSN is considered invalid, restoring the helpfulness of the previous error reporting.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: src/OptionsResolver.php#L47-L59

Potential issue: The new `OptionsResolver` performs eager validation on default values
at construction time. If the `SENTRY_DSN` environment variable is set to an invalid
value, the `Options` constructor immediately throws a generic
`InvalidArgumentException('Invalid default for option "dsn"')`. This behavior is a
regression, as the previous implementation would fail later with a more descriptive
error. The current generic exception prevents developers from understanding what is
wrong with the DSN string, hindering debugging.

Did we get this right? 👍 / 👎 to inform future reviews.

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.

1 participant