taplo icon indicating copy to clipboard operation
taplo copied to clipboard

Throws error about unknown license

Open Ten0 opened this issue 1 year ago • 8 comments
trafficstars

Specifying LGPL-3.0-only license in my Cargo.toml has Even Better Toml complain:

"LGPL-3.0-only" is not valid under any of the given schemas

image

That doesn't seem correct, as Cargo uses SPDX identifiers, and this is the correct SPDX identifier for LGPL v3.0.

Ten0 avatar Jan 30 '24 16:01 Ten0

Same problem here, using MIT

Mettwasser avatar Jan 30 '24 19:01 Mettwasser

Came to also comment I am getting this error.

Just to add some additional debug/troubleshooting information, the following commands are run with taplo --version = taplo 0.8.1.

Steps to reproduce:

  • Create a new project (cargo new foo)
  • Add license = "MIT" to foo/Cargo.toml
  • Observe error upon running taplo --verbose check --default-schema-catalogs foo/Cargo.toml

Possible root cause

Digging through the cli source, it looks like --default-schema-catalogs points to https://www.schemastore.org/api/json/catalog.json, which in turn uses https://json.schemastore.org/cargo.json. This schema has the following for the license key:

"license": {
  "anyOf": [
    {
      "$ref": "#/definitions/License"
    },
    {
      "$ref": "#/definitions/WorkspaceInheritance"
    }
  ]
},

Following the references around eventually leads to https://json.schemastore.org/base.json#/definitions/license, which does indeed have the correct schema (the osi-license reference is just a list of all valid identifiers):

"license": {
  "$id": "license",
  "anyOf": [
    {
      "$ref": "https://json.schemastore.org/base.json#/definitions/osi-license"
    },
    {
      "type": "string"
    }
  ]
},

Perhaps there's something going wrong with the $ref chain? I haven't dug too far into the cli source to see how the schemas are resolved.

Test cases

Description: Using the default schema catalogs, I get the error. Command: taplo --verbose check --default-schema-catalogs Cargo.toml.json Cargo.toml Output:

  2024-01-31T03:04:12.401559Z  INFO taplo_cli: found files, total: 1, excluded: 0
    at crates\taplo-cli\src\lib.rs:139
    in taplo_cli::collect_files with cwd="X:/foo"
    in taplo_cli::commands::lint::lint_files
    in taplo::taplo

error: "MIT" is not valid under any of the schemas listed in the 'anyOf' keyword
  ┌─ X:/foo/Cargo.toml:7:11
  │
7 │ license = "MIT"
  │           ^^^^^ "MIT" is not valid under any of the schemas listed in the 'anyOf' keyword

  2024-01-31T03:04:13.092740Z ERROR taplo_cli::commands::lint: invalid file, error: schema validation failed, path: "X:/foo/Cargo.toml"
    at crates\taplo-cli\src\commands\lint.rs:87
    in taplo_cli::commands::lint::lint_files
    in taplo::taplo

  2024-01-31T03:04:13.092774Z ERROR taplo: operation failed, error: some files were not valid
    at crates\taplo-cli\bin/taplo.rs:33

Description: Using the current Cargo.toml.json schema on the master branch I don't get any errors. Command: taplo --verbose check --schema https://raw.githubusercontent.com/tamasfe/taplo/268c8b1de41c105324b8c667460aeb5e23b0b6da/site/site/public/schemas/Cargo.toml.json Cargo.toml Output:

  2024-01-31T03:08:00.766020Z  INFO taplo_cli: found files, total: 1, excluded: 0
    at crates\taplo-cli\src\lib.rs:139
    in taplo_cli::collect_files with cwd="X:/foo"
    in taplo_cli::commands::lint::lint_files
    in taplo::taplo

From the verbose output, it's not clear if the check is actually running or not, but assuming no errors/warnings is a good thing.

bwpge avatar Jan 31 '24 03:01 bwpge

Apologies to double post but on a more positive note: it seems like using the schema directive works, so this can be a temporary workaround for those with Cargo.toml issues.

Add the previously mentioned schema file at the top of Cargo.toml:

#:schema https://raw.githubusercontent.com/tamasfe/taplo/268c8b1de41c105324b8c667460aeb5e23b0b6da/site/site/public/schemas/Cargo.toml.json

[package]
# ...
license = "MIT"

You can verify the lint/check works correctly by setting license to a non-string value, e.g., license = 5. As a side note, you can also create the schema file locally and reference it with #:schema ./foo.json (note the path is relative to Cargo.toml).

bwpge avatar Jan 31 '24 04:01 bwpge

Same issue for license = "MIT OR Apache-2.0".

ihciah avatar Jan 31 '24 07:01 ihciah

Same issue for license = "MIT OR Apache-2.0".

Also started having issues with this recently.

jessebraham avatar Jan 31 '24 15:01 jessebraham

This is most likely caused by https://github.com/SchemaStore/schemastore/pull/3519

panekj avatar Jan 31 '24 15:01 panekj

I went ahead and reverted https://github.com/SchemaStore/schemastore/pull/3519 out of caution (https://github.com/SchemaStore/schemastore/pull/3568). I suspect that has something to do with it, even though it passed the test suite we have there and I also included a fallback for "any string".

hyperupcall avatar Feb 02 '24 19:02 hyperupcall

it might be what validate-pyproject reported, which is not loading nested referenced schemas

panekj avatar Feb 02 '24 22:02 panekj