dart_custom_lint icon indicating copy to clipboard operation
dart_custom_lint copied to clipboard

custom_lint fails to run "pub get" on Windows with spaces in paths

Open DanTup opened this issue 9 months ago • 3 comments

When trying to repro an issue for @pattobrien, I noticed custom_lint was failing to start:

The request analysis.setContextRoots failed with the following error:
RequestErrorCode.PLUGIN_ERROR
Exception: Failed to run "pub get" in the client project:
Resolving dependencies...

Because custom_lint_client depends on custom_lint_lsp_bug from path which doesn't exist (could not find package custom_lint_lsp_bug at "d:/Dev/Temp%20Projects/custom_lint_lsp_bug"), version solving failed.

at:
#0      CustomLintWorkspace.runPubGet (package:custom_lint/src/workspace.dart:772:7)
<asynchronous suspension>
#1      CustomLintWorkspace.resolvePluginHost (package:custom_lint/src/workspace.dart:757:5)
<asynchronous suspension>
#2      SocketCustomLintServerToClientChannel._startProcess (package:custom_lint/src/v2/server_to_client_channel.dart:151:7)
<asynchronous suspension>
#3      SocketCustomLintServerToClientChannel.init (package:custom_lint/src/v2/server_to_client_channel.dart:111:21)
<asynchronous suspension>
#4      CustomLintServer._maybeSpawnCustomLintPlugin (package:custom_lint/src/v2/custom_lint_analyzer_plugin.dart:394:5)
<asynchronous suspension>
#5      CustomLintServer._handleAnalysisSetContextRoots.<anonymous closure> (package:custom_lint/src/v2/custom_lint_analyzer_plugin.dart:341:9)
<asynchronous suspension>
#6      PendingOperation.run (package:custom_lint/src/async_operation.dart:22:14)
<asynchronous suspension>
#7      CustomLintServer._handleRequest (package:custom_lint/src/v2/custom_lint_analyzer_plugin.dart:173:22)
<asynchronous suspension>

The issue is that the pubspec.yaml that gets generated looks contains:

dependencies:
  custom_lint_lsp_bug:
    path: "d:/Dev/Temp%20Projects/custom_lint_lsp_bug"

I don't know if this is supposed to be a path or a URI, but as a path the %20 is not valid. If I run pub get in this folder I see the same error as above, but if I replace it with a space, then it works.

DanTup avatar May 22 '25 15:05 DanTup

The path comes from here:

https://github.com/invertase/dart_custom_lint/blob/3aaed0c7ed283c1c4e4702d38e4200f1526c14a0/packages/custom_lint/lib/src/workspace.dart#L130-L132

The input (sharedConstraint.path) is "D:\Dev\Temp Projects\custom_lint_lsp_bug" and the output is "d:/Dev/Temp%20Projects/custom_lint_lsp_bug".

DanTup avatar May 22 '25 15:05 DanTup

Not using posix.prettyUri() works for me, though I don't know if it's the right thing in all cases:

// Use appropriate path separators across platforms
return '\n    path: ${jsonEncode(sharedConstraint.path)}';

results in:

dependencies:
  custom_lint_lsp_bug:
    path: "D:\\Dev\\Temp Projects\\custom_lint_lsp_bug"

And this works fine.

DanTup avatar May 22 '25 15:05 DanTup

Thanks for the detailed report!

rrousselGit avatar May 23 '25 11:05 rrousselGit