Skip to content

Improve privileged mode error message with actionable suggestions#448

Open
danielschlegel wants to merge 6 commits into
mainfrom
fix-issue-326-suggest-privileged-mode
Open

Improve privileged mode error message with actionable suggestions#448
danielschlegel wants to merge 6 commits into
mainfrom
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 5557
This PR 5569
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
…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
@kmannislands kmannislands enabled auto-merge (squash) April 29, 2026 16:43
@danielschlegel danielschlegel self-assigned this Apr 30, 2026
Comment thread cmd/earthly/app/run.go
Comment on lines +271 to +276
var flagExample string
if targetInfo != "" {
flagExample = fmt.Sprintf("earth -P %s", targetInfo)
} else {
flagExample = "earth -P +your-target"
}
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.

Both code samples compile to the same binary code

Suggested change
var flagExample string
if targetInfo != "" {
flagExample = fmt.Sprintf("earth -P %s", targetInfo)
} else {
flagExample = "earth -P +your-target"
}
flagExample := "earth -P +your-target"
if targetInfo != "" {
flagExample = fmt.Sprintf("earth -P %s", targetInfo)
}

Comment thread cmd/earthly/app/run.go
)
app.BaseCLI.Console().HelpPrint(helpMsg)

app.BaseCLI.Console().VerboseWarnf("Technical details: %v\n", err.Error())
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.

Suggested change
app.BaseCLI.Console().VerboseWarnf("Technical details: %v\n", err.Error())
app.BaseCLI.Console().VerboseWarnf("Error: %s\n", err.Error())

RUN test -f /the-prescript-was-run
END

# Cache bust for CI
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.

What is this comment for?

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

4 participants