Skip to content

Gracefully handle missing .env file in Program.cs #47

@coderabbitai

Description

@coderabbitai

Problem

Currently, the application crashes during startup if the .env file is missing because OsmoDoc.API.DotEnv.Load(dotenv) throws an exception when the file doesn't exist. This can cause issues during local development when the .env file is not present.

Location

File: OsmoDoc.API/Program.cs around lines 24-27

Suggested Solution

Check if the .env file exists using File.Exists(dotenv) before calling Load, and only call Load if the file is present. This prevents the application from crashing during local development when the .env file is absent.

Example Fix

string root = Directory.GetCurrentDirectory();
string dotenv = Path.GetFullPath(Path.Combine(root, "..", ".env"));
if (File.Exists(dotenv))
{
    OsmoDoc.API.DotEnv.Load(dotenv);
}

References

Metadata

Metadata

Assignees

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