Skip to content

Pub commands crash when $HOME is not set #3167

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

Closed
akbiggs opened this issue Oct 1, 2021 · 5 comments · Fixed by #3164
Closed

Pub commands crash when $HOME is not set #3167

akbiggs opened this issue Oct 1, 2021 · 5 comments · Fixed by #3164
Labels
type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@akbiggs
Copy link

akbiggs commented Oct 1, 2021

Environment

  • pub version or flutter pub version: Dart SDK version: 2.15.0-edge.e08ee7abecd889a55bee49afe635ea620b28b93e (be) (Wed Sep 15 00:43:22 2021 +0000) on "linux_x64"
  • OS version: linux_x64

Problem

You can make pub crash by unsetting the $HOME variable. This breaks tools that run pub in a clean environment without any environment variables. Example repro instructions

$ unset $HOME
$ dart pub get

Expected behavior

pub does not crash.

Actual behavior

Invalid argument(s): join(null, ".config"): part 0 was null, but part 1 was not.
package:path/src/context.dart 1102:5               _validateArgList
package:path/src/context.dart 242:5                Context.join
package:path/path.dart 265:13                      join
package:pub/src/io.dart 1007:14                    dartConfigDir.<fn>
package:pub/src/io.dart 1017:2                     dartConfigDir
package:pub/src/io.dart                            dartConfigDir
package:pub/src/system_cache.dart 92:33            new SystemCache
package:pub/src/command.dart 51:39                 PubCommand.cache
package:pub/src/command.dart 65:70                 PubCommand.entrypoint
package:pub/src/command/get.dart 54:11             GetCommand.runProtected
dart:async                                         new Future.sync
package:pub/src/utils.dart 112:12                  captureErrors.wrappedCallback
dart:async                                         runZonedGuarded
package:pub/src/utils.dart 129:5                   captureErrors
package:pub/src/command.dart 171:13                PubCommand.run
package:args/command_runner.dart 209:27            CommandRunner.runCommand
package:dartdev/dartdev.dart 222:30                DartdevRunner.runCommand
package:args/command_runner.dart 119:25            CommandRunner.run.<fn>
dart:async                                         new Future.sync
package:args/command_runner.dart 119:14            CommandRunner.run
package:dartdev/dartdev.dart 66:29                 runDartdev
../dart-sdk/sdk/pkg/dartdev/bin/dartdev.dart 11:9  main
@akbiggs
Copy link
Author

akbiggs commented Oct 1, 2021

I believe that this is because of #3092 which relies on the $HOME environment variable to determine where to store config details on Linux and unknown operating systems.

@sigurdm
Copy link
Contributor

sigurdm commented Oct 5, 2021

Not being very familiar with Fuschia, Is there any good location for putting app-specific configuration?, then platform specific logic for that could be integrated into the code (that now lives here: https://github.com/dart-lang/cli_util/blob/master/lib/cli_util.dart#L87) feel free to answer here or just making a PR.

@akbiggs
Copy link
Author

akbiggs commented Oct 5, 2021

@sigurdm Fuchsia isn't really the issue here (note that this issue does not mention Fuchsia). The issue is that we have tools that run pub get without setting any environment variables (including $HOME). We don't set any environment variables in these tests because we want to create a clean hermetic environment.

Can you talk in more detail about why every command requires the TokenStore to work? pub get shouldn't care about a ~/.config/dart directory AFAICT.

@sigurdm
Copy link
Contributor

sigurdm commented Oct 7, 2021

Can you talk in more detail about why every command requires the TokenStore to work? pub get shouldn't care about a ~/.config/dart directory AFAICT.

For a pub get we reach out for the token store to see if we have tokens to send to the package-servers.

But I agree, if we cannot find a config-dir we should just truck on without any tokens instead of crashing :) . I think we simply did not consider the environment without a $HOME folder valid when designing this - but I guess for some hermetic environments it would be.

FWIW a posix environment must have a HOME variable set at the time of login: https://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap08.html (in part 8.3):

The system shall initialize this variable at the time of login to be a pathname of the user's home directory.

That of course does not limit you from unsetting it later or running dart in a non-posix environment.

The only solution I see right now is changing the type of https://github.com/dart-lang/cli_util/blob/master/lib/cli_util.dart#L87 String? returning null if we cannot find a place to look for the config. In that case pub get would simply run without tokens, and pub token add/pub login would fail.

@jonasfj will be with us next week - maybe he has some insight.

@sigurdm sigurdm added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label Oct 7, 2021
@jonasfj
Copy link
Member

jonasfj commented Oct 11, 2021

But I agree, if we cannot find a config-dir we should just truck on without any tokens instead of crashing :)

I agree, I think we just didn't imagine an environment without @HOME defined.
We should probably push forward with changes in dart-archive/cli_util#68

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants