Skip to content

[Bounty: $90] Remove the unreachable missing-baseUrl error path in LilySdk.create and align its JSDoc with the DEFAULT_API_URL fallback #441

Description

@Philo016

Context
LilySdk.create in src/sdk.ts resolves baseUrl as options?.baseUrl ?? process.env.LILY_API_URL ?? process.env.LILY_BASE_URL ?? DEFAULT_API_URL, so the result is always a non-empty string. The very next statement, if (!baseUrl) throw new Error('baseUrl is required. ... LILY_API_URL environment variable.'), is dead code that can never execute, and the method's JSDoc ("Throws if no baseUrl is provided and no env var is set.") contradicts the code, which silently falls back to the public DEFAULT_API_URL. Only the constructor path genuinely throws for a missing baseUrl (resolveBaseUrl in src/config/resolve-config.ts raises LilyConfigError: baseUrl is required.), so the two documented construction routes advertise different error contracts.

Proposed Change
Remove the unreachable guard (or convert it into an assertion that the fallback is defined) and rewrite the LilySdk.create JSDoc to describe the actual precedence — explicit options.baseUrl > LILY_API_URL > LILY_BASE_URL > DEFAULT_API_URL — and to note that only the constructor throws for a missing baseUrl. Update tests/sdk-create-factory.test.ts/related sdk-create tests to pin the precedence chain and confirm create() never throws solely for a missing baseUrl.

Acceptance Criteria

  • LilySdk.create() with no options and no env vars constructs an SDK pointed at DEFAULT_API_URL, with no throw.
  • The if (!baseUrl) branch is removed or proven reachable by a test.
  • The JSDoc documents the exact fallback order and no longer claims a missing-baseUrl error.
  • Tests cover options-over-env precedence and confirm the constructor (not create()) is the path that raises LilyConfigError.

Suggested Label (documentation)

ETA: 24 hours

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions