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

Taplo CLI doesn't validate schemas if using schema catalog and cache and cache is existed #523

Closed
hituzi-no-sippo opened this issue Dec 29, 2023 · 4 comments · Fixed by #524
Labels
bug Something isn't working cli

Comments

@hituzi-no-sippo
Copy link
Contributor

Taplo CLI doesn't validate schemas if using schema catalog (--default-schema-catalogs, --schema-catalog <SCHEMA_CATALOG>) and --cach-path and Taplo cache is existed.

If use schema instead of schema catalog, that is, if using --schema <SCHEMA> and --cach-path and Taplo cache is existed, Taplo CLI validates schemas.

reproduce.sh

#!/usr/bin/env bash

wget --quiet --output-document taplo.gz https://github.com/tamasfe/taplo/releases/download/0.8.1/taplo-linux-x86_64.gz
gzip --decompress taplo.gz
chmod +x ./taplo
./taplo --version

declare toml_file='release-plz.toml'
echo -e '[[package]]\nname = 1' > "$toml_file"

set -x
./taplo lint --cache-path ./ --default-schema-catalogs "$toml_file"
ls

./taplo lint --cache-path ./ --default-schema-catalogs "$toml_file"
./taplo lint --cache-path ./ --schema-catalog https://www.schemastore.org/api/json/catalog.json "$toml_file"
./taplo lint --cache-path ./ --schema https://raw.githubusercontent.com/MarcoIeni/release-plz/main/.schema/latest.json "$toml_file"

Result

$ bash reproduce.sh
taplo 0.8.1
+ ./taplo lint --cache-path ./ --default-schema-catalogs release-plz.toml
INFO taplo:lint_files:collect_files: found files total=1 excluded=0 cwd="/home/hituzi_no_sippo/taplo_schema"
error: 1 is not of type "string"
┌─ /home/hituzi_no_sippo/taplo_schema/release-plz.toml:2:8

2 │ name = 1
│        ^ 1 is not of type "string"

ERROR taplo:lint_files: invalid file error=schema validation failed path="/home/hituzi_no_sippo/taplo_schema/release-plz.toml"
ERROR operation failed error=some files were not valid
+ ls
5b16e32f1334ff5b75ab387d99f1de40eeea4924  f6c331111c3dbf4da601b1da5a14bb49b3f362f0  release-plz.toml  reproduce.sh  taplo
+ ./taplo lint --cache-path ./ --default-schema-catalogs release-plz.toml
INFO taplo:lint_files:collect_files: found files total=1 excluded=0 cwd="/home/hituzi_no_sippo/taplo_schema"
+ ./taplo lint --cache-path ./ --schema-catalog https://www.schemastore.org/api/json/catalog.json release-plz.toml
INFO taplo:lint_files:collect_files: found files total=1 excluded=0 cwd="/home/hituzi_no_sippo/taplo_schema"
+ ./taplo lint --cache-path ./ --schema https://raw.githubusercontent.com/MarcoIeni/release-plz/main/.schema/latest.json release-plz.toml
INFO taplo:lint_files:collect_files: found files total=1 excluded=0 cwd="/home/hituzi_no_sippo/taplo_schema"
error: 1 is not of type "string"
┌─ /home/hituzi_no_sippo/taplo_schema/release-plz.toml:2:8

2 │ name = 1
│        ^ 1 is not of type "string"

ERROR taplo:lint_files: invalid file error=schema validation failed path="/home/hituzi_no_sippo/taplo_schema/release-plz.toml"
ERROR operation failed error=some files were not valid
$

System

  • OS Ubuntu 20.04 LTS (WSL2)
  • Version: taplo 0.8.1

Thanks.

@ia0
Copy link
Collaborator

ia0 commented Dec 29, 2023

Thanks for the bug report! I can reproduce. This looks indeed like a cache-related bug. It will need some investigation.

@ia0 ia0 added bug Something isn't working needs investigation cli labels Dec 29, 2023
ia0 added a commit to ia0/taplo that referenced this issue Dec 30, 2023
@ia0
Copy link
Collaborator

ia0 commented Dec 30, 2023

After investigation, the problem was that before being used, the index was transformed, such that the pattern was **/release-plz.toml instead of release-plz.toml. But this transformation was not saved to the cache and was not applied neither when loading from the cache, and thus no schema was found for the file.

@ia0
Copy link
Collaborator

ia0 commented Dec 30, 2023

You can install the latest version with cargo install taplo-cli --git=https://github.com/tamasfe/taplo.git --features=lsp.

@hituzi-no-sippo
Copy link
Contributor Author

hituzi-no-sippo commented Dec 31, 2023

You can install the latest version with cargo install taplo-cli --git=https://github.com/tamasfe/taplo.git --features=lsp.

I've checked.
Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cli
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants