Skip to content

fix: fail with a clear error when LD_SDK_KEY is unset - #19

Draft
devin-ai-integration[bot] wants to merge 2 commits into
mainfrom
devin/1788167314-guard-missing-sdk-key
Draft

fix: fail with a clear error when LD_SDK_KEY is unset#19
devin-ai-integration[bot] wants to merge 2 commits into
mainfrom
devin/1788167314-guard-missing-sdk-key

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Summary

Running the example without LD_SDK_KEY crashed with a multi-thousand-line supervisor report (the whole TLS options map dumped twice), because os:getenv/1 returns the atom false — not "" — when the variable is unset, and that atom went straight into ldclient:start_instance/2.

  • hello_erlang_server:init/1 now returns {stop, "LD_SDK_KEY is not set. ..."} for a missing or empty key, matching the hello-elixir example's behaviour.
  • Boot then fails fast with a readable one-line reason instead of an unreadable crash dump.
  • No dependency changes: ldclient 3.11.2 is the latest release in the current major, and rebar3 upgrade --all reports every locked transitive dependency already at its latest resolvable version.
  • No deprecated SDK APIs and no deprecation warnings when compiling or running.
Implementation details
init(_Args) ->
  case os:getenv("LD_SDK_KEY") of
    SdkKey when SdkKey =:= false; SdkKey =:= "" ->
      {stop, "LD_SDK_KEY is not set. Set it to your LaunchDarkly server-side SDK key and try again."};
    SdkKey ->
      ldclient:start_instance(SdkKey, #{http_options => #{tls_options => ldclient_config:tls_basic_options()}}),
      {ok, []}
  end.

An earlier revision of this PR started the client in offline mode instead; per review feedback it now fails loudly, since a silently-offline example that always returns fallbacks is more confusing than a startup error.

Testing (Erlang/OTP 27 via docker run erlang:27, rebar3 compile + rebar3 shell):

  • With a real server SDK key: streaming connection established, hello_erlang_server:get(<<"hello-boolean">>, false, <<"user-key-123abc">>) returned the flag value from LaunchDarkly.
  • With LD_SDK_KEY unset: ===> Failed to boot hello_erlang for reason {{shutdown,{failed_to_start_child,console,"LD_SDK_KEY is not set. ..."}}, ...}.

Not a UI change, so no screenshots or staging link apply.

Link to Devin session: https://app.devin.ai/sessions/39c567ec09c14cb3973cb2f73337f733
Open in Devin Desktop: https://app.devin.ai/desktop/session/39c567ec09c14cb3973cb2f73337f733?variant=devin

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

@cursor review

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would prefer failing with a clear error like the elixir example.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in 6335ee3init/1 now returns {stop, "LD_SDK_KEY is not set. Set it to your LaunchDarkly server-side SDK key and try again."}, same as the Elixir example, instead of starting offline. Boot output with the key unset:

===> Failed to boot hello_erlang for reason {{shutdown,
                                              {failed_to_start_child,console,
                                               "LD_SDK_KEY is not set. Set it to your LaunchDarkly server-side SDK key and try again."}},
                                             {hello_erlang_app,start,[normal,[]]}}

Re-verified with a real SDK key that the flag still evaluates.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration devin-ai-integration Bot changed the title fix: start the LaunchDarkly client offline when LD_SDK_KEY is unset fix: fail with a clear error when LD_SDK_KEY is unset Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant