-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Error encountered while parsing package_config.json: Unexpected end of input #59992
Comments
Summary: After updating the Dart SDK, the user encounters "Unexpected end of input" while parsing |
The only place I can find this error string is here: sdk/pkg/dartdev/lib/src/native_assets.dart Lines 120 to 122 in 6417e1c
But it's not clear what's going wrong. I'm unable to reproduce the issue. Both the original stack trace that led to this call and also the path of the (cc @bkonyi in case you have any ideas, I think you've been worked on some of this code). |
@dcharkes owns the native assets work, so maybe he'll know? |
Thanks for the report @FMorschel! I've recently reorganized this code to be more strict in requiring a The error message sounds like the package config is read while it's being written to by some other process. I'll add the path to the error message. I also think we should consider not failing early in this function, but let dartdev fail later, if the package config isn't valid. |
Not to me, can this message be improved @dcharkes, so that it is clearer to the user? Hopefully, this won't happen again but still. |
The message comes straight from (Yes not concurrent modification, but an empty file or a file that was partially flushed or something.) |
Bug: #59992 Change-Id: If7aff2aeecbab347f5bcb997e6fd6043e8818e1b Cq-Include-Trybots: luci.dart.try:pkg-linux-debug-try,pkg-linux-release-arm64-try,pkg-linux-release-try,pkg-mac-release-arm64-try,pkg-mac-release-try,pkg-win-release-arm64-try,pkg-win-release-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/406280 Commit-Queue: Daco Harkes <[email protected]> Reviewed-by: Ben Konyi <[email protected]>
Alright, more weirdness for us: I just ran Connecting to VM Service at ws://127.0.0.1:52972/Ux9X7SyE-vw=/ws
Connected to the VM Service.
Error encountered while parsing C:\Users\felip_0vh5fa6\Documents\Projects\clones\dart-sdk2\sdk\.dart_tool\package_config.json: Unexpected end of input.
00:00 +0: AddMissingHashOrEqualsTest | test_equals
00:03 +1: AddMissingHashOrEqualsTest | test_equals_fieldHashCode
00:04 +2: AddMissingHashOrEqualsTest | test_hashCode
00:04 +3: CreateMethodMixinTest | test_createQualified_instance
00:05 +4: CreateMethodMixinTest | test_createQualified_static
00:06 +5: CreateMethodMixinTest | test_createUnqualified
00:06 +6: CreateMethodMixinTest | test_functionType_method_enclosingMixin_static
00:06 +7: CreateMethodMixinTest | test_functionType_method_targetMixin
00:07 +8: CreateMethodTest | test_createQualified_emptyClassBody
00:07 +9: CreateMethodTest | test_createQualified_fromClass
00:07 +10: CreateMethodTest | test_createQualified_fromClass_hasOtherMember
00:07 +11: CreateMethodTest | test_createQualified_fromExtensionType
00:07 +12: CreateMethodTest | test_createQualified_fromInstance
00:08 +13: CreateMethodTest | test_createQualified_instance_fromExtensionType
00:08 +14: CreateMethodTest | test_createQualified_targetIsFunctionType
00:08 +15: CreateMethodTest | test_createQualified_targetIsUnresolved
00:08 +16: CreateMethodTest | test_createUnqualified_duplicateArgumentNames
00:09 +17: CreateMethodTest | test_createUnqualified_instanceField
00:09 +18: CreateMethodTest | test_createUnqualified_instanceField_late
00:09 +19: CreateMethodTest | test_createUnqualified_parameters
00:09 +20: CreateMethodTest | test_createUnqualified_parameters_named
00:09 +21: CreateMethodTest | test_createUnqualified_returnType
00:09 +22: CreateMethodTest | test_createUnqualified_staticField
00:10 +23: CreateMethodTest | test_createUnqualified_staticField_late
00:10 +24: CreateMethodTest | test_createUnqualified_staticFromMethod
00:10 +25: CreateMethodTest | test_functionType_argument
00:10 +26: CreateMethodTest | test_functionType_method_enclosingClass_instance
00:11 +27: CreateMethodTest | test_functionType_method_enclosingClass_static
00:11 +28: CreateMethodTest | test_functionType_method_enclosingClass_static2
00:11 +29: CreateMethodTest | test_functionType_method_FunctionCall
00:12 +30: CreateMethodTest | test_functionType_method_inside_conditional_operator_condition
00:12 +31: CreateMethodTest | test_functionType_method_inside_conditional_operator_condition_FunctionCall
00:12 +32: CreateMethodTest | test_functionType_method_inside_conditional_operator_else
00:12 +33: CreateMethodTest | test_functionType_method_inside_conditional_operator_else_FunctionCall
00:13 +34: CreateMethodTest | test_functionType_method_inside_conditional_operator_then
00:13 +35: CreateMethodTest | test_functionType_method_inside_conditional_operator_then_FunctionCall
00:13 +36: CreateMethodTest | test_functionType_method_inside_record_functionType
00:14 +37: CreateMethodTest | test_functionType_method_inside_record_functionType_named
00:14 +38: CreateMethodTest | test_functionType_method_targetClass
00:14 +39: CreateMethodTest | test_functionType_method_targetClass_hasOtherMember
00:14 +40: CreateMethodTest | test_functionType_notFunctionType
00:14 +41: CreateMethodTest | test_functionType_unknownTarget
00:15 +42: CreateMethodTest | test_generic_argumentType
00:15 +43: CreateMethodTest | test_generic_literal
00:15 +44: CreateMethodTest | test_generic_local
00:15 +45: CreateMethodTest | test_generic_returnType
00:16 +46: CreateMethodTest | test_hint_createQualified_fromInstance
00:16 +47: CreateMethodTest | test_inSDK
00:16 +48: CreateMethodTest | test_internal_instance
00:16 +49: CreateMethodTest | test_internal_static
00:17 +50: CreateMethodTest | test_override
00:17 +51: CreateMethodTest | test_parameterType_differentPrefixInTargetUnit
00:17 +52: CreateMethodTest | test_parameterType_inTargetUnit
00:17 +53: CreateMethodTest | test_static
00:17 +54: CreateMethodTest | test_targetIsEnum
00:18 +55: All tests passed!
Exited. There was a big delay between the error message and everything else. But as I mentioned in a talk on Discord, the file in question is the one I sent over and the last modification date is yesterday morning (when I did the deletion of all |
That is odd. I wonder if a stack trace would help to know exactly who is throwing this. I thought this was coming from
(@FMorschel have you ever built the SDK locally before? (something like |
Yes, I have. It is slow but doable. |
In that case, you could try changing the code here: sdk/pkg/dartdev/lib/src/native_assets.dart Line 117 in 6417e1c
To have Perhaps it's also worth verifying the encoding of that file - for me it shows UTF-8, but I don't know if the encoding it's written with might be influenced by settings on the system. |
It is also UTF-8.
Building... Will update you with a new comment on what I find. |
Here is the stacktrace: Error encountered while parsing C:\Users\felip_0vh5fa6\Documents\Projects\clones\dart-sdk2\sdk\.dart_tool\package_config.json: Unexpected end of input.
The stack trace for the error is:
#0 _ChunkedJsonParser.fail (dart:convert-patch/convert_patch.dart:1463:5)
#1 _ChunkedJsonParser.close (dart:convert-patch/convert_patch.dart:497:7)
#2 _parseJson (dart:convert-patch/convert_patch.dart:36:10)
#3 JsonDecoder.convert (dart:convert/json.dart:641:36)
#4 JsonCodec.decode (dart:convert/json.dart:223:41)
#5 jsonDecode (dart:convert/json.dart:160:12)
#6 new PackageGraph.fromPubDepsJsonString (package:native_assets_builder/src/build_runner/build_planner.dart:151:36)
#7 NativeAssetsBuildPlanner.fromPackageConfigUri (package:native_assets_builder/src/build_runner/build_planner.dart:51:22)
<asynchronous suspension>
#8 NativeAssetsBuildRunner._planner.<anonymous closure> (package:native_assets_builder/src/build_runner/build_runner.dart:759:21)
<asynchronous suspension>
#9 NativeAssetsBuildRunner.packagesWithBuildHooks (package:native_assets_builder/src/build_runner/build_runner.dart:92:21)
<asynchronous suspension>
#10 DartNativeAssetsBuilder.warnOnNativeAssets (package:dartdev/src/native_assets.dart:159:28)
<asynchronous suspension>
#11 RunCommand.run (package:dartdev/src/commands/run.dart:389:15)
<asynchronous suspension>
#12 CommandRunner.runCommand (package:args/command_runner.dart:212:13)
<asynchronous suspension>
#13 DartdevRunner.runCommand (package:dartdev/dartdev.dart:240:18)
<asynchronous suspension>
#14 runDartdev (package:dartdev/dartdev.dart:47:16)
<asynchronous suspension>
#15 main (file:///C:/Users/felip_0vh5fa6/Documents/Projects/clones/dart-sdk2/sdk/pkg/dartdev/bin/dartdev.dart:13:5)
dartdev.dart:13
<asynchronous suspension> I'll keep trying out different things on my end, any suggestions are appreciated. |
Over at final workingDirectory = packageConfigUri.resolve('../');
logger.severe('Running `dart pub deps --json` in $workingDirectory'); // New line
final result = await Process.run(
dartExecutable.toFilePath(),
[
'pub',
'deps',
'--json',
],
workingDirectory: workingDirectory.toFilePath(),
);
logger.severe('json data: "${result.stdout}"'); // New line
logger.severe('error: "${result.stderr}"'); // New line
final packageGraph = PackageGraph.fromPubDepsJsonString(result.stdout as String); // Throwing line And above the previously suggested change: Future<bool> warnOnNativeAssets() async {
try {
_logger.onRecord.listen((record) => log.stderr(record.message)); // New line
final builder = await _nativeAssetsBuildRunner;
final packageNames = await builder.packagesWithBuildHooks();
if (packageNames.isEmpty) return false;
log.stderr(
'Package(s) $packageNames require the native assets feature to be enabled. '
'Enable native assets with `--enable-experiment=native-assets`.',
);
return true;
} on FormatException catch (e, s) {
// ... These are the new lines I got on the debug console: Running `dart pub deps --json` in file:///C:/Users/felip_0vh5fa6/Documents/Projects/clones/dart-sdk2/sdk/
json data: ""
error: "Found no `pubspec.yaml` file in `C:\Users\felip_0vh5fa6\Documents\Projects\clones\dart-sdk2\sdk` or parent directories" Now we know why it is failing for me but I still don't think I understand why it is not failing for any of you. |
Okay, my thoughts so far. In order to know the "root package" inside a pub workspace, we need to find the nearest pub spec. Also, in order to find the order in which to run build hooks (if the experiment is enabled), we need run this pub command to get a dependency graph. Before my change, Taking a step back, we don't support using packages with native assets in the SDK itself (currently). So
I don't understand this either, there is no top level @bkonyi What is the contract that we want to enforce for
Dart without a command has no concept of pubspecs and the package manager. If we want to enforce contract 1. Then the SDK should not be trying to run any If we want to enforce contract 2, Then (a) The package_config.json would need to be extended to include the dependency graph, and (b) So I'm leaning towards saying that the contract should be 1. And that |
I made the same changes as @FMorschel and built the SDK locally and tried to run So I tested back with my previous SDK, and I also see the error. My only conclusion is that I only previously tested with "Run" (which works) and not "Debug" (I'm surprised, since I'm sure I was debugging tests just yesterday, but it's my only good theory). So, things are definitely broken.
I was actually mistaken - we are not using
However I'm not sure if internally it gets rewritten (@bkonyi?). Knowing that it only occurred in the debug mode, I was actually able to trivially reproduce this from the command line by just passing
|
Now I'm wondering why all of the tests aren't broken... Surely between both Dart and the DAP tests, we should be triggering this a lot? Edit: Maybe all of the DAP tests have a |
I see some interesting code here: sdk/runtime/bin/main_options.cc Lines 646 to 649 in 671bbe9
sdk/runtime/bin/main_options.cc Lines 745 to 750 in 671bbe9
Maybe this is splicing in |
I was literally just looking at this code when you commented @dcharkes! I thought Siva had removed this logic once we moved to spawning DDS from the VM Service isolate instead of DartDev. Basically, since DartDev was responsible for spawning the DDS process we needed to implicitly add the |
What's the intended difference between (I presume there's still a bug here to fix even if that's changed though?) |
I can't reproduce this on MacOS. 🤷 Before I fire up a Windows machine, anyone on a Windows machine wants to try removing the referenced code?
In my understanding
Probably not. Because the implicit |
WIP CL to remove the implicit DartDev behavior here. |
Sure, I'll test with Ben's CL shortly.
Ah, yes :) |
I built an SDK from Ben's change, but now I get a weirder error: And the same from the terminal:
I don't know where that error is coming from, but in the case of the full absolute path, the file definitely exists because I can ctrl+click it in the VS Code output and it opens the file. Edit: I tried passing a file URI in case something was expecting that, but it made no difference:
|
I might have broken something in my CL, so I wouldn't look too deeply into that error quite yet. |
@DanTup I've uploaded a fix for the issue you're seeing if you'd like to try it again (I was unconditionally skipping the first argument by accident). |
Yep, that works as expected now :-) |
I've been contributing for months now and on Thursday last week I updated my SDK again following https://gsdview.appspot.com/dart-archive/channels/main/raw/latest/sdk/. Now after that change, even my open CLs and when I checkout origin/main, I'm unable to run any code (basically tests) on my clone (though VS Code). I've tried debugging this with @DanTup but neither of us has an idea on how to continue this.
I've tried:
git rebase-update
git reset --hard
git clean
.git
) andgit reset --hard
.dart_tool
folders andgit reset --hard
All of the above running
gclient sync
. I downloaded a new SDK on Friday and today again, but still no luck.This is the output:
Here is a capture of debugging logs (even though @DanTup said there was nothing that would help) Dart-Code-Log-2025-00-01 09-08-44.txt (added the
package_config.json
file below but from my human parsing it seems alright).Here is my vscode workspace file (had to add the trailing
.txt
since GitHub doesn't accept the extension) server.code-workspace.txt which is basically a copy of what @DanTup uses.On the debugging logs above, I tried running
pkg\analysis_server\test\services\completion\dart\completion_test.dart
and created and tried runningpkg/analysis_server/bin/a.dart
which was a file containing only:Running either on the terminal with my SDK downloaded from the link above showed no issue.
package_config.json
it found the problem but our guess is.dart_tool/package_config.json
from the root of the project (package_config.json)-v
todart run
on the workspace file above at thelaunch
.The text was updated successfully, but these errors were encountered: