Skip to content

Improve privileged mode error message with actionable suggestions#448

Open
danielschlegel wants to merge 3 commits intomainfrom
fix-issue-326-suggest-privileged-mode
Open

Improve privileged mode error message with actionable suggestions#448
danielschlegel wants to merge 3 commits intomainfrom
fix-issue-326-suggest-privileged-mode

Conversation

@danielschlegel
Copy link
Copy Markdown
Collaborator

@danielschlegel danielschlegel commented Apr 14, 2026

Replace cryptic 'unlazy force execution: failed to load LLB: security.insecure is not allowed' error with clear, user-friendly message.

Changes:

  • cmd/earthly/app/run.go: Create clear error message with 3 solution options

    • Run with -P flag
    • Set EARTHLY_ALLOW_PRIVILEGED environment variable
    • Add to config file
    • Technical details only shown with -V or --debug flags
  • logbus/formatter/formatter.go: Print help message for build failures

  • tests/with-docker/Earthfile: Add simple test target for privileged tests

  • tests/Earthfile: Add comprehensive tests for all privileged operations

    • RUN --privileged
    • WITH DOCKER
    • IF --privileged
    • FOR --privileged

Before:
Error: build target: build main: failed to solve: unlazy force execution:
failed to load LLB: security.insecure is not allowed
Help: earth --allow-privileged (earth -P) flag is required

After:
Error: This build uses privileged operations which requires privileged mode.
Help: To fix this, use one of the following:
• Run with the -P flag: earthly -P +your-target • Set environment variable: export EARTHLY_ALLOW_PRIVILEGED=true • Add to config: earthly config global.allow_privileged true

Fixes #326

@danielschlegel danielschlegel requested a review from a team as a code owner April 14, 2026 18:05
@danielschlegel danielschlegel requested review from kmannislands and removed request for a team April 14, 2026 18:05
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 14, 2026

⚠️ Are we earthbuild yet?

Warning: "earthly" occurrences have increased by 12 (0.22%)

📈 Overall Progress

Branch Total Count
main 5577
This PR 5589
Difference +12 (0.22%)

📁 Changes by file type:

File Type Change
Go files (.go) ❌ +8
Documentation (.md) ➖ No change
Earthfiles ❌ +4

Keep up the great work migrating from Earthly to Earthbuild! 🚀

💡 Tips for finding more occurrences

Run locally to see detailed breakdown:

./.github/scripts/count-earthly.sh

Note that the goal is not to reach 0.
There is anticipated to be at least some occurences of earthly in the source code due to backwards compatibility with config files and language constructs.

@danielschlegel danielschlegel force-pushed the fix-issue-326-suggest-privileged-mode branch from ffc8803 to 282f9d6 Compare April 14, 2026 18:05
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request improves the error messaging when a build requires privileged mode but the -P flag is missing. It introduces more descriptive user messages, including target information when available, and provides clear instructions on how to resolve the issue. Additionally, it moves the help message printing to the logbus formatter and adds comprehensive integration tests. Feedback includes addressing potential duplicate output caused by the architectural change in the formatter, fixing a grammatical error in the user message, and removing a redundant flag check before calling VerboseWarnf.

Comment thread logbus/formatter/formatter.go
Comment thread cmd/earthly/app/run.go Outdated
Comment thread cmd/earthly/app/run.go Outdated
@danielschlegel danielschlegel force-pushed the fix-issue-326-suggest-privileged-mode branch 4 times, most recently from 1c5e841 to 9729fdd Compare April 15, 2026 09:18
Replace cryptic 'unlazy force execution: failed to load LLB: security.insecure
is not allowed' error with clear, user-friendly message.

Changes:
- cmd/earthly/app/run.go: Create clear error message with 3 solution options
  * Run with -P flag
  * Set EARTHLY_ALLOW_PRIVILEGED environment variable
  * Add to config file
  * Technical details only shown with -V or --debug flags

- logbus/formatter/formatter.go: Print help message for build failures

- tests/with-docker/Earthfile: Add simple test target for privileged tests

- tests/Earthfile: Add comprehensive tests for all privileged operations
  * RUN --privileged
  * WITH DOCKER
  * IF --privileged
  * FOR --privileged

Before:
  Error: build target: build main: failed to solve: unlazy force execution:
         failed to load LLB: security.insecure is not allowed
  Help: earth --allow-privileged (earth -P) flag is required

After:
  Error: This build uses privileged operations which requires privileged mode.
  Help: To fix this, use one of the following:
    • Run with the -P flag: earth -P +your-target
    • Set environment variable: export EARTHLY_ALLOW_PRIVILEGED=true
    • Add to config: earth config global.allow_privileged true

Clean up error handling: remove duplicate HelpPrint calls and simplify verbose warning
@danielschlegel danielschlegel force-pushed the fix-issue-326-suggest-privileged-mode branch from 9729fdd to 5ebf72a Compare April 15, 2026 10:02
@danielschlegel danielschlegel mentioned this pull request Apr 15, 2026
Comment thread cmd/earthly/app/run.go Outdated
}

helpMsg := "To fix this, use one of the following:\n" +
" • Run with the -P flag: earth -P +your-target\n" +
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we infer the target at this point? If the user executed earth +foobar, we can provide meaningful feedback ... earth -P +foobar....

Copy link
Copy Markdown
Collaborator Author

@danielschlegel danielschlegel Apr 22, 2026

Choose a reason for hiding this comment

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

…f placeholder

- Extract target from command line arguments when not available from interpreter error
- Show specific command like 'earth -P +foobar' instead of generic 'earth -P +your-target'
- Add comprehensive test suite for target extraction logic
- Addresses feedback from @janishorsts to provide more meaningful error messages

Fixes the issue where users had to mentally substitute the target placeholder
with their actual target name in privileged mode error suggestions.
Comment thread cmd/earthly/app/run.go
}

// If no target info from interpreter error, try to extract from args
if targetInfo == "" && len(args) > 1 {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hmm this is CLI args? We might not want this fallback.

Interpreter should capture this in the error it throws since we very likely have target a executing b which calls c and so on.

Repeating the top level target the user called which may not be where -P is required is not very helpful

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.

Suggest

3 participants