Skip to content

Avoid panicking when the startup working directory is unavailable - #275

Open
2836048681 wants to merge 1 commit into
go-macaron:mainfrom
2836048681:fix/175-working-directory-init
Open

2836048681 wants to merge 1 commit into
go-macaron:mainfrom
2836048681:fix/175-working-directory-init

Conversation

@2836048681

Copy link
Copy Markdown

When Macaron is imported by a program whose startup working directory cannot be resolved, os.Getwd() can fail and package initialization panics before main runs. This also prevents subcommands that never use Macaron from starting.

Leave macaron.Root empty when the startup directory cannot be determined, and keep setting it to the absolute startup directory when lookup succeeds. This preserves the existing behavior for normal startup and lets the application choose an explicit root if it needs one.

Fixes #175.

Testing

  • A Linux subprocess removes its current directory and reruns package initialization. The test reproduced the getwd: no such file or directory panic on the base branch and passes with the fix, verifying Root is empty.
  • go test -count=1 -v ./... passed on Linux with Go 1.27.4.

Local handoff

The branch is in repo/; fix-175.patch contains the commit. No changes were pushed or posted to GitHub.

Fixes #175.

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Macaron causes panic on starting gogs/gitea in an unwritable/unreadable directory

1 participant