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

avoid printing full error during development #59

Merged
merged 5 commits into from
Feb 5, 2025

Conversation

dferber90
Copy link
Collaborator

@dferber90 dferber90 commented Feb 5, 2025

When developing locally it is common to create a feature flag in code before actually creating it in the feature flag provider, and to then use Flags Explorer to override this flag and continue development.

This works fine when a defaultValue is declared. However the feature flag provider will - expectedly - not find the feature flag yet, and usually emit an error. This has the negative effect that we currently print the whole error the flag provider emits to the console, even though this is expected. This is quite distracting.

This PR reduces the log level by downgrading the log to a console.info, and by omitting the error itself from the log.

Before

@vercel/flags: Flag "example-flag" is falling back to the defaultValue after catching the following error Error: test
    at Object.decide (app/concepts/identify/basic/flags.ts:21:10)
    at decide (../../packages/flags/src/next/index.ts:173:24)
    at run (../../packages/flags/src/next/index.ts:286:8)
    at async Page (app/concepts/identify/basic/page.tsx:5:16)

After

@vercel/flags: Flag "example-flag" is falling back to its defaultValue

For preview and production environments we continue to show the full error, as you would expect the feature flag to be declared in those environments.

To see the full error during development you can temporarily remove the defaultValue from the declaration, which will make the flag function throw the actual error.

Alternatives considered

  • Using console.groupCollapsed to log the warning and show the full error in a collapsed state during development.
  • Allowing customers to handle errors manually as shown in Allow intercepting evaluations #58

Copy link

vercel bot commented Feb 5, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
flags-sdk-snippets ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 5, 2025 3:40pm
summer-sale ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 5, 2025 3:40pm

@dferber90 dferber90 merged commit 6955b68 into main Feb 5, 2025
12 checks passed
@dferber90 dferber90 deleted the avoid-printing-error-in-development branch February 5, 2025 15:55
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.

2 participants