Skip to content

Show specific error message for dotnet <app_path> where app_path is a non-dll/exe file that exists #116940

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 23, 2025

Currently, when a user runs dotnet <app_path> and the host determines that <app_path> is not a runnable app, it's treated as a CLI command and routed to the SDK, which shows a generic error message.

This PR improves the user experience by detecting when the user passes a path to an existing non-dll/exe file and showing a specific error message instead of routing to the SDK.

Changes Made

Core Logic Enhancement:

  • Added new status code AppArgNotManagedFailure (0x80008090) using an unused error code slot
  • Enhanced argument parsing in command_line.cpp to detect the specific scenario:
    • File is not managed (.dll/.exe)
    • Path contains directory separator
    • File exists
    • Not in exec mode
  • Added specific error handling in fx_muxer.cpp with clear error message

Behavior Change:

Before:

$ dotnet /path/to/config.json
Could not execute because the specified command or file was not found.
Possible reasons for this include:
  You misspelled a built-in dotnet command.
  You intended to execute a .NET program, but dotnet-/path/to/config.json does not exist.
  You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.

After:

$ dotnet /path/to/config.json
The application '/path/to/config.json' does not exist or is not a managed .dll or .exe.

Preserves Existing Behavior:

  • Commands without directory separators (like dotnet build) still route to SDK
  • dotnet exec behavior unchanged
  • All existing error codes and messages unchanged

Test Coverage

Added comprehensive tests covering:

  • Absolute paths with directory separators
  • Relative paths like ./subdir/file.txt
  • Commands without separators still route to SDK
  • Backward compatibility verification

All existing tests pass, confirming no regressions.

Fixes #116939.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits June 23, 2025 23:22
… separators

Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Show specific error message for dotnet <app_path> where <app_path> is a non-dll/exe file that exists Show specific error message for dotnet <app_path> where app_path is a non-dll/exe file that exists Jun 23, 2025
Copilot finished work on behalf of elinor-fung June 23, 2025 23:30
@Copilot Copilot AI requested a review from elinor-fung June 23, 2025 23:30
@@ -572,6 +572,11 @@ int fx_muxer_t::execute(
return result;
}
}
else if (static_cast<StatusCode>(result) == AppArgNotManagedFailure)
{
trace::error(_X("The application '%s' does not exist or is not a managed .dll or .exe."), app_candidate.c_str());
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
trace::error(_X("The application '%s' does not exist or is not a managed .dll or .exe."), app_candidate.c_str());
trace::error(_X("The application '%s' is not a managed .dll or .exe."), app_candidate.c_str());

This error code is returned above only when the file actually exists

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the error message to remove "does not exist or" since this error code is only returned when the file actually exists. Changes committed in d2dd638.

…reporting

Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
@Copilot Copilot AI requested a review from jkotas June 24, 2025 00:14
Copilot finished work on behalf of jkotas June 24, 2025 00:14
…error directly in command_line.cpp

Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
@Copilot Copilot AI requested a review from elinor-fung June 24, 2025 02:03
Copilot finished work on behalf of elinor-fung June 24, 2025 02:03
…tions, remove test file

Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
@Copilot Copilot AI requested a review from elinor-fung June 24, 2025 18:39
Copilot finished work on behalf of elinor-fung June 24, 2025 18:39
…k lines, simplify test tracing calls

Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
@Copilot Copilot AI requested a review from elinor-fung June 24, 2025 20:09
Copilot finished work on behalf of elinor-fung June 24, 2025 20:09
Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
string testFile = Path.Combine(sharedTestState.BaseDirectory.Location, "subdir", "test.json");
File.WriteAllText(testFile, "{}");

string relativePath = "./subdir/test.json";
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
string relativePath = "./subdir/test.json";
string relativePath = Path.GetRelativePath(sharedTestState.BaseDirectory.Location, testFile);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to use Path.GetRelativePath(sharedTestState.BaseDirectory.Location, testFile) for dynamic path computation. This makes the test more robust and maintainable. Changes committed in df74861.

Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
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.

Show specific error message for dotnet <app_path> where <app_path> is a non-dll/exe file that exists
3 participants