Skip to content
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

better error message for conda config json parsing? #163

Closed
tdhock opened this issue Oct 3, 2024 · 2 comments · Fixed by #164
Closed

better error message for conda config json parsing? #163

tdhock opened this issue Oct 3, 2024 · 2 comments · Fixed by #164
Labels

Comments

@tdhock
Copy link

tdhock commented Oct 3, 2024

Hi! thanks for maintaining conda.el which I find useful!

I tried installing it on a new windows computer, with a fresh miniconda install today.

First I configuring the path to my conda install in .emacs as usual via:

(setq conda-anaconda-home (expand-file-name "~/AppData/Local/miniconda3"))
(setq conda-env-home-directory conda-anaconda-home)

Then usually M-x conda-env-activate works fine.

This time I got an error, something like invalid stringp (forget exact wording), in the minibuffer.

I used edebug to figure out the root issue. Call stack is ...

  • conda--get-config
  • conda--call-json
    which has (json-read-from-string output) in which output had some FutureWarning text as below (non-JSON data). You can simulate the issue via the code below which has the data on my system that was causing the error
(json-read-from-string "c:\\Users\\hoct2726\\AppData\\Local\\miniconda3\\lib\\site-packages\\conda\\base\\context.py:982: FutureWarning: Adding 'defaults' to the channel list implicitly is deprecated and will be removed in 25.3. 

To remove this warning, please choose a default channel explicitly via 'conda config --add channels <name>', e.g. 'conda config --add channels defaults'.
  deprecated.topic(
{
  \"add_anaconda_token\": true,
  \"add_pip_as_python_dependency\": true,
  \"aggressive_update_packages\": [
    \"ca-certificates\",
    \"certifi\",
    \"openssl\"
  ],
  \"allow_conda_downgrades\": false,
  \"allow_cycles\": true,
  \"allow_non_channel_urls\": false,
  \"allow_softlinks\": false,
  \"allowlist_channels\": [],
  \"always_copy\": false,
  \"always_softlink\": false,
  \"always_yes\": null,
  \"anaconda_anon_usage\": true,
  \"anaconda_upload\": null,
  \"auto_activate_base\": true,
  \"auto_stack\": 0,
  \"auto_update_conda\": true,
  \"bld_path\": \"\",
  \"changeps1\": true,
  \"channel_alias\": {
    \"auth\": null,
    \"location\": \"conda.anaconda.org\",
    \"name\": \"\",
    \"package_filename\": null,
    \"platform\": null,
    \"scheme\": \"https\",
    \"token\": null
  },
  \"channel_priority\": \"flexible\",
  \"channel_settings\": [],
  \"channels\": [
    \"defaults\"
  ],
  \"client_ssl_cert\": null,
  \"client_ssl_cert_key\": null,
  \"clobber\": false,
  \"conda_build\": {},
  \"create_default_packages\": [],
  \"croot\": \"c:\\\\Users\\\\hoct2726\\\\AppData\\\\Local\\\\miniconda3\\\\conda-bld\",
  \"custom_channels\": {
    \"pkgs/main\": {
      \"auth\": null,
      \"location\": \"repo.anaconda.com\",
      \"name\": \"pkgs/main\",
      \"package_filename\": null,
      \"platform\": null,
      \"scheme\": \"https\",
      \"token\": null
    },
    \"pkgs/msys2\": {
      \"auth\": null,
      \"location\": \"repo.anaconda.com\",
      \"name\": \"pkgs/msys2\",
      \"package_filename\": null,
      \"platform\": null,
      \"scheme\": \"https\",
      \"token\": null
    },
    \"pkgs/pro\": {
      \"auth\": null,
      \"location\": \"repo.anaconda.com\",
      \"name\": \"pkgs/pro\",
      \"package_filename\": null,
      \"platform\": null,
      \"scheme\": \"https\",
      \"token\": null
    },
    \"pkgs/r\": {
      \"auth\": null,
      \"location\": \"repo.anaconda.com\",
      \"name\": \"pkgs/r\",
      \"package_filename\": null,
      \"platform\": null,
      \"scheme\": \"https\",
      \"token\": null
    }
  },
  \"custom_multichannels\": {
    \"defaults\": [
      {
        \"auth\": null,
        \"location\": \"repo.anaconda.com\",
        \"name\": \"pkgs/main\",
        \"package_filename\": null,
        \"platform\": null,
        \"scheme\": \"https\",
        \"token\": null
      },
      {
        \"auth\": null,
        \"location\": \"repo.anaconda.com\",
        \"name\": \"pkgs/r\",
        \"package_filename\": null,
        \"platform\": null,
        \"scheme\": \"https\",
        \"token\": null
      },
      {
        \"auth\": null,
        \"location\": \"repo.anaconda.com\",
        \"name\": \"pkgs/msys2\",
        \"package_filename\": null,
        \"platform\": null,
        \"scheme\": \"https\",
        \"token\": null
      }
    ],
    \"local\": []
  },
  \"debug\": false,
  \"default_channels\": [
    {
      \"auth\": null,
      \"location\": \"repo.anaconda.com\",
      \"name\": \"pkgs/main\",
      \"package_filename\": null,
      \"platform\": null,
      \"scheme\": \"https\",
      \"token\": null
    },
    {
      \"auth\": null,
      \"location\": \"repo.anaconda.com\",
      \"name\": \"pkgs/r\",
      \"package_filename\": null,
      \"platform\": null,
      \"scheme\": \"https\",
      \"token\": null
    },
    {
      \"auth\": null,
      \"location\": \"repo.anaconda.com\",
      \"name\": \"pkgs/msys2\",
      \"package_filename\": null,
      \"platform\": null,
      \"scheme\": \"https\",
      \"token\": null
    }
  ],
  \"default_python\": \"3.10\",
  \"default_threads\": null,
  \"denylist_channels\": [],
  \"deps_modifier\": \"not_set\",
  \"dev\": false,
  \"disallowed_packages\": [],
  \"download_only\": false,
  \"dry_run\": false,
  \"enable_private_envs\": false,
  \"env_prompt\": \"({default_env}) \",
  \"envs_dirs\": [
    \"c:\\\\Users\\\\hoct2726\\\\AppData\\\\Local\\\\miniconda3\\\\envs\",
    \"C:\\\\Users\\\\hoct2726\\\\.conda\\\\envs\",
    \"C:\\\\Users\\\\hoct2726\\\\AppData\\\\Local\\\\conda\\\\conda\\\\envs\"
  ],
  \"envvars_force_uppercase\": true,
  \"error_upload_url\": \"https://conda.io/conda-post/unexpected-error\",
  \"execute_threads\": 1,
  \"experimental\": [],
  \"extra_safety_checks\": false,
  \"fetch_threads\": 5,
  \"force\": false,
  \"force_32bit\": false,
  \"force_reinstall\": false,
  \"force_remove\": false,
  \"ignore_pinned\": false,
  \"json\": true,
  \"local_repodata_ttl\": 1,
  \"migrated_channel_aliases\": [],
  \"migrated_custom_channels\": {},
  \"no_lock\": false,
  \"no_plugins\": false,
  \"non_admin_enabled\": true,
  \"notify_outdated_conda\": true,
  \"number_channel_notices\": 5,
  \"offline\": false,
  \"override_channels_enabled\": true,
  \"path_conflict\": \"clobber\",
  \"pinned_packages\": [],
  \"pip_interop_enabled\": false,
  \"pkgs_dirs\": [
    \"c:\\\\Users\\\\hoct2726\\\\AppData\\\\Local\\\\miniconda3\\\\pkgs\",
    \"C:\\\\Users\\\\hoct2726\\\\.conda\\\\pkgs\",
    \"C:\\\\Users\\\\hoct2726\\\\AppData\\\\Local\\\\conda\\\\conda\\\\pkgs\"
  ],
  \"proxy_servers\": {},
  \"quiet\": false,
  \"register_envs\": true,
  \"remote_backoff_factor\": 1,
  \"remote_connect_timeout_secs\": 9.15,
  \"remote_max_retries\": 3,
  \"remote_read_timeout_secs\": 60.0,
  \"repodata_fns\": [
    \"current_repodata.json\",
    \"repodata.json\"
  ],
  \"repodata_threads\": null,
  \"repodata_use_zst\": true,
  \"report_errors\": null,
  \"reporters\": [
    {
      \"backend\": \"json\",
      \"output\": \"stdout\",
      \"quiet\": false,
      \"verbosity\": 0
    }
  ],
  \"restore_free_channel\": false,
  \"rollback_enabled\": true,
  \"root_prefix\": \"c:\\\\Users\\\\hoct2726\\\\AppData\\\\Local\\\\miniconda3\",
  \"safety_checks\": \"warn\",
  \"sat_solver\": \"pycosat\",
  \"separate_format_cache\": false,
  \"shortcuts\": true,
  \"shortcuts_only\": [],
  \"show_channel_urls\": null,
  \"signing_metadata_url_base\": null,
  \"solver\": \"libmamba\",
  \"solver_ignore_timestamps\": false,
  \"ssl_verify\": true,
  \"subdir\": \"win-64\",
  \"subdirs\": [
    \"win-64\",
    \"noarch\"
  ],
  \"target_prefix_override\": \"\",
  \"trace\": false,
  \"track_features\": [],
  \"unsatisfiable_hints\": true,
  \"unsatisfiable_hints_check_depth\": 2,
  \"update_modifier\": \"update_specs\",
  \"use_index_cache\": false,
  \"use_local\": false,
  \"use_only_tar_bz2\": null,
  \"verbosity\": 0,
  \"verify_threads\": 1
}
")

The work-around that I used was to read the warning, and use the conda config commands that were suggested, until the warnings went away, and conda config returns just JSON data as below (no warnings)

(json-read-from-string "
{
  \"add_anaconda_token\": true,
  \"add_pip_as_python_dependency\": true,
  \"aggressive_update_packages\": [
    \"ca-certificates\",
    \"certifi\",
    \"openssl\"
  ],
  \"allow_conda_downgrades\": false,
  \"allow_cycles\": true,
  \"allow_non_channel_urls\": false,
  \"allow_softlinks\": false,
  \"allowlist_channels\": [],
  \"always_copy\": false,
  \"always_softlink\": false,
  \"always_yes\": null,
  \"anaconda_anon_usage\": true,
  \"anaconda_upload\": null,
  \"auto_activate_base\": true,
  \"auto_stack\": 0,
  \"auto_update_conda\": true,
  \"bld_path\": \"\",
  \"changeps1\": true,
  \"channel_alias\": {
    \"auth\": null,
    \"location\": \"conda.anaconda.org\",
    \"name\": \"\",
    \"package_filename\": null,
    \"platform\": null,
    \"scheme\": \"https\",
    \"token\": null
  },
  \"channel_priority\": \"flexible\",
  \"channel_settings\": [],
  \"channels\": [
    \"defaults\"
  ],
  \"client_ssl_cert\": null,
  \"client_ssl_cert_key\": null,
  \"clobber\": false,
  \"conda_build\": {},
  \"create_default_packages\": [],
  \"croot\": \"c:\\\\Users\\\\hoct2726\\\\AppData\\\\Local\\\\miniconda3\\\\conda-bld\",
  \"custom_channels\": {
    \"pkgs/main\": {
      \"auth\": null,
      \"location\": \"repo.anaconda.com\",
      \"name\": \"pkgs/main\",
      \"package_filename\": null,
      \"platform\": null,
      \"scheme\": \"https\",
      \"token\": null
    },
    \"pkgs/msys2\": {
      \"auth\": null,
      \"location\": \"repo.anaconda.com\",
      \"name\": \"pkgs/msys2\",
      \"package_filename\": null,
      \"platform\": null,
      \"scheme\": \"https\",
      \"token\": null
    },
    \"pkgs/pro\": {
      \"auth\": null,
      \"location\": \"repo.anaconda.com\",
      \"name\": \"pkgs/pro\",
      \"package_filename\": null,
      \"platform\": null,
      \"scheme\": \"https\",
      \"token\": null
    },
    \"pkgs/r\": {
      \"auth\": null,
      \"location\": \"repo.anaconda.com\",
      \"name\": \"pkgs/r\",
      \"package_filename\": null,
      \"platform\": null,
      \"scheme\": \"https\",
      \"token\": null
    }
  },
  \"custom_multichannels\": {
    \"defaults\": [
      {
        \"auth\": null,
        \"location\": \"repo.anaconda.com\",
        \"name\": \"pkgs/main\",
        \"package_filename\": null,
        \"platform\": null,
        \"scheme\": \"https\",
        \"token\": null
      },
      {
        \"auth\": null,
        \"location\": \"repo.anaconda.com\",
        \"name\": \"pkgs/r\",
        \"package_filename\": null,
        \"platform\": null,
        \"scheme\": \"https\",
        \"token\": null
      },
      {
        \"auth\": null,
        \"location\": \"repo.anaconda.com\",
        \"name\": \"pkgs/msys2\",
        \"package_filename\": null,
        \"platform\": null,
        \"scheme\": \"https\",
        \"token\": null
      }
    ],
    \"local\": []
  },
  \"debug\": false,
  \"default_channels\": [
    {
      \"auth\": null,
      \"location\": \"repo.anaconda.com\",
      \"name\": \"pkgs/main\",
      \"package_filename\": null,
      \"platform\": null,
      \"scheme\": \"https\",
      \"token\": null
    },
    {
      \"auth\": null,
      \"location\": \"repo.anaconda.com\",
      \"name\": \"pkgs/r\",
      \"package_filename\": null,
      \"platform\": null,
      \"scheme\": \"https\",
      \"token\": null
    },
    {
      \"auth\": null,
      \"location\": \"repo.anaconda.com\",
      \"name\": \"pkgs/msys2\",
      \"package_filename\": null,
      \"platform\": null,
      \"scheme\": \"https\",
      \"token\": null
    }
  ],
  \"default_python\": \"3.10\",
  \"default_threads\": null,
  \"denylist_channels\": [],
  \"deps_modifier\": \"not_set\",
  \"dev\": false,
  \"disallowed_packages\": [],
  \"download_only\": false,
  \"dry_run\": false,
  \"enable_private_envs\": false,
  \"env_prompt\": \"({default_env}) \",
  \"envs_dirs\": [
    \"c:\\\\Users\\\\hoct2726\\\\AppData\\\\Local\\\\miniconda3\\\\envs\",
    \"C:\\\\Users\\\\hoct2726\\\\.conda\\\\envs\",
    \"C:\\\\Users\\\\hoct2726\\\\AppData\\\\Local\\\\conda\\\\conda\\\\envs\"
  ],
  \"envvars_force_uppercase\": true,
  \"error_upload_url\": \"https://conda.io/conda-post/unexpected-error\",
  \"execute_threads\": 1,
  \"experimental\": [],
  \"extra_safety_checks\": false,
  \"fetch_threads\": 5,
  \"force\": false,
  \"force_32bit\": false,
  \"force_reinstall\": false,
  \"force_remove\": false,
  \"ignore_pinned\": false,
  \"json\": true,
  \"local_repodata_ttl\": 1,
  \"migrated_channel_aliases\": [],
  \"migrated_custom_channels\": {},
  \"no_lock\": false,
  \"no_plugins\": false,
  \"non_admin_enabled\": true,
  \"notify_outdated_conda\": true,
  \"number_channel_notices\": 5,
  \"offline\": false,
  \"override_channels_enabled\": true,
  \"path_conflict\": \"clobber\",
  \"pinned_packages\": [],
  \"pip_interop_enabled\": false,
  \"pkgs_dirs\": [
    \"c:\\\\Users\\\\hoct2726\\\\AppData\\\\Local\\\\miniconda3\\\\pkgs\",
    \"C:\\\\Users\\\\hoct2726\\\\.conda\\\\pkgs\",
    \"C:\\\\Users\\\\hoct2726\\\\AppData\\\\Local\\\\conda\\\\conda\\\\pkgs\"
  ],
  \"proxy_servers\": {},
  \"quiet\": false,
  \"register_envs\": true,
  \"remote_backoff_factor\": 1,
  \"remote_connect_timeout_secs\": 9.15,
  \"remote_max_retries\": 3,
  \"remote_read_timeout_secs\": 60.0,
  \"repodata_fns\": [
    \"current_repodata.json\",
    \"repodata.json\"
  ],
  \"repodata_threads\": null,
  \"repodata_use_zst\": true,
  \"report_errors\": null,
  \"reporters\": [
    {
      \"backend\": \"json\",
      \"output\": \"stdout\",
      \"quiet\": false,
      \"verbosity\": 0
    }
  ],
  \"restore_free_channel\": false,
  \"rollback_enabled\": true,
  \"root_prefix\": \"c:\\\\Users\\\\hoct2726\\\\AppData\\\\Local\\\\miniconda3\",
  \"safety_checks\": \"warn\",
  \"sat_solver\": \"pycosat\",
  \"separate_format_cache\": false,
  \"shortcuts\": true,
  \"shortcuts_only\": [],
  \"show_channel_urls\": null,
  \"signing_metadata_url_base\": null,
  \"solver\": \"libmamba\",
  \"solver_ignore_timestamps\": false,
  \"ssl_verify\": true,
  \"subdir\": \"win-64\",
  \"subdirs\": [
    \"win-64\",
    \"noarch\"
  ],
  \"target_prefix_override\": \"\",
  \"trace\": false,
  \"track_features\": [],
  \"unsatisfiable_hints\": true,
  \"unsatisfiable_hints_check_depth\": 2,
  \"update_modifier\": \"update_specs\",
  \"use_index_cache\": false,
  \"use_local\": false,
  \"use_only_tar_bz2\": null,
  \"verbosity\": 0,
  \"verify_threads\": 1
}
")

It would be great if conda.el could give the user a better error message in the minibuffer, something like "json-read-from-string failed, please run conda config --show --json in the anaconda shell, and read the warnings, and act to suppress them"

another fix would be to change the conda command line program to emit these warning in stderr instead of stdout, which I think would fix the "parsing failed issue" do you agree? if so I will file an issue in https://github.com/conda/conda/issues
but it still would be good to get a better error message, please.

also inside of conda--call-json I saw this let binding (fmt (format "shell.%s+json" (if (eq system-type 'windows-nt) "cmd.exe" "posix"))) but fmt is not used after that, so I wonder if it could be deleted?

necaris added a commit that referenced this issue Oct 5, 2024
Fixes #163. Discards the standard error from the `conda` command,
ensuring that it _should_ be more consistently parseable as JSON.
@necaris
Copy link
Owner

necaris commented Oct 5, 2024

@tdhock Thank you for the report! Any chance you could try the branch at #164 and let me know if that fixes things? It fixes it in my testing locally, so 🤞🏽

@necaris necaris added the bug label Oct 5, 2024
necaris added a commit that referenced this issue Oct 5, 2024
Fixes #163. Discards the standard error from the `conda` command,
ensuring that it _should_ be more consistently parseable as JSON.
@necaris necaris closed this as completed in 05de0c8 Oct 5, 2024
@tdhock
Copy link
Author

tdhock commented Oct 7, 2024

the new version ignores the non-json header, and so yes it works on my system. thanks!
I'm not sure if parsing could fail for any other reason, but if so, a better error message would be appreciated, something like "conda.el tried to parse the stdout of the shell command 'conda config --show --json' as JSON, but parsing failed, so please try running that command to see why that is not valid JSON"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants