ComPWA / taplo-pre-commit

A pre-commit hook for Taplo, a TOML formatter written in Rust
https://github.com/tamasfe/taplo
12 stars 3 forks source link

`taplo` pre-commit hook fails to compile #6

Closed kbumsik closed 1 year ago

kbumsik commented 1 year ago

Bug description

When I run pre-commit in a fresh environment, I started getting compilation error.

How to reproduce?

Steps to reproduce the behavior:

  1. in a fresh environment
  2. Run pre-commit run taplo -a
  3. I get a compile error:

    pre-commit run taplo -a                                             
    [INFO] Installing environment for https://github.com/ComPWA/mirrors-taplo.
    [INFO] Once installed this environment will be reused.
    [INFO] This may take a few minutes...
    An unexpected error has occurred: CalledProcessError: command: ('/home/liam/.cache/pre-commit/repo4xw166n3/rustenv-default/bin/cargo', 'install', '--bins', '--root', '/home/liam/.cache/pre-commit/repo4xw166n3/rustenv-default', 'taplo-cli', '--version', '0.8.1')
    return code: 101
    stdout: (none)
    stderr:
        Updating crates.io index
      Installing taplo-cli v0.8.1
        Updating crates.io index
       Compiling proc-macro2 v1.0.66
       Compiling unicode-ident v1.0.12
       Compiling autocfg v1.1.0
       Compiling libc v0.2.147
       Compiling cfg-if v1.0.0
       Compiling version_check v0.9.4
       Compiling serde v1.0.188
       Compiling memchr v2.6.3
       Compiling once_cell v1.18.0
       Compiling itoa v1.0.9
       Compiling scopeguard v1.2.0
       Compiling pin-project-lite v0.2.13
       Compiling syn v1.0.109
       Compiling crossbeam-utils v0.8.16
       Compiling ryu v1.0.15
       Compiling futures-core v0.3.28
       Compiling smallvec v1.11.0
       Compiling parking_lot_core v0.9.8
       Compiling futures-task v0.3.28
       Compiling futures-sink v0.3.28
       Compiling futures-channel v0.3.28
       Compiling tinyvec_macros v0.1.1
       Compiling bytes v1.5.0
       Compiling serde_json v1.0.106
       Compiling rayon-core v1.11.0
       Compiling percent-encoding v2.3.0
       Compiling equivalent v1.0.1
       Compiling either v1.9.0
       Compiling futures-util v0.3.28
       Compiling hashbrown v0.14.0
       Compiling futures-io v0.3.28
       Compiling fnv v1.0.7
       Compiling pin-utils v0.1.0
       Compiling unicode-bidi v0.3.13
       Compiling lazy_static v1.4.0
       Compiling log v0.4.20
       Compiling regex-syntax v0.7.5
       Compiling untrusted v0.7.1
       Compiling spin v0.5.2
       Compiling typenum v1.16.0
       Compiling unicode-width v0.1.10
       Compiling gimli v0.28.0
       Compiling rustls v0.21.7
       Compiling httparse v1.8.0
       Compiling bitflags v1.3.2
       Compiling adler v1.0.2
       Compiling rustix v0.38.13
       Compiling time-core v0.1.1
       Compiling rustc-demangle v0.1.23
       Compiling try-lock v0.2.4
       Compiling anyhow v1.0.75
       Compiling beef v0.5.2
       Compiling tower-service v0.3.2
       Compiling bit-vec v0.6.3
       Compiling thiserror v1.0.48
       Compiling regex-syntax v0.6.29
       Compiling httpdate v1.0.3
       Compiling unicode-segmentation v1.10.1
       Compiling minimal-lexical v0.2.1
       Compiling rustc-hash v1.1.0
       Compiling countme v3.0.1
       Compiling bitflags v2.4.0
       Compiling linux-raw-sys v0.4.7
       Compiling async-trait v0.1.73
       Compiling base64 v0.21.4
       Compiling schemars v0.8.13
       Compiling text-size v1.1.1
       Compiling dyn-clone v1.0.13
       Compiling semver v1.0.18
       Compiling strsim v0.8.0
       Compiling overload v0.1.1
       Compiling ansi_term v0.12.1
       Compiling vec_map v0.8.2
       Compiling cpufeatures v0.2.9
       Compiling arc-swap v1.6.0
       Compiling mime v0.3.17
       Compiling heck v0.4.1
       Compiling bytecount v0.6.3
       Compiling encode_unicode v1.0.0
       Compiling ipnet v2.8.0
       Compiling num-cmp v0.1.0
       Compiling webpki-roots v0.25.2
       Compiling os_str_bytes v6.5.1
       Compiling termcolor v1.2.0
       Compiling uuid v1.4.1
       Compiling strsim v0.10.0
       Compiling glob v0.3.1
       Compiling hex v0.4.3
       Compiling textwrap v0.16.0
       Compiling tap v1.0.1
       Compiling ahash v0.7.6
       Compiling memoffset v0.9.0
       Compiling lock_api v0.4.10
       Compiling crossbeam-epoch v0.9.15
       Compiling tracing-core v0.1.31
       Compiling num-traits v0.2.16
       Compiling slab v0.4.9
       Compiling tinyvec v1.6.0
       Compiling num-integer v0.1.45
       Compiling form_urlencoded v1.2.0
       Compiling indexmap v1.9.3
       Compiling proc-macro-error-attr v1.0.4
       Compiling num-bigint v0.4.4
       Compiling generic-array v0.14.7
       Compiling proc-macro-error v1.0.4
       Compiling num-iter v0.1.43
       Compiling num-rational v0.4.1
       Compiling memoffset v0.8.0
       Compiling miniz_oxide v0.7.1
       Compiling time-macros v0.2.14
       Compiling ahash v0.8.3
       Compiling want v0.3.1
       Compiling textwrap v0.11.0
       Compiling thread_local v1.1.7
       Compiling encoding_rs v0.8.33
       Compiling sharded-slab v0.1.4
       Compiling itertools v0.10.5
       Compiling pad v0.1.6
       Compiling indexmap v2.0.0
       Compiling aho-corasick v1.0.5
       Compiling http v0.2.9
       Compiling object v0.32.1
       Compiling bstr v1.6.2
       Compiling csv-core v0.1.10
       Compiling heck v0.3.3
       Compiling nom v7.1.3
       Compiling bit-set v0.5.3
       Compiling rustls-pemfile v1.0.3
       Compiling nu-ansi-term v0.46.0
       Compiling clap_lex v0.2.4
       Compiling codespan-reporting v0.11.1
       Compiling tracing-log v0.1.3
       Compiling crossbeam-channel v0.5.8
       Compiling getrandom v0.2.10
       Compiling num_cpus v1.16.0
       Compiling socket2 v0.5.4
       Compiling mio v0.8.8
       Compiling atty v0.2.14
       Compiling dirs-sys-next v0.1.2
       Compiling socket2 v0.4.9
       Compiling quote v1.0.33
       Compiling clap v2.34.0
       Compiling cc v1.0.83
       Compiling unicode-normalization v0.1.22
       Compiling dirs-next v2.0.0
       Compiling parking_lot v0.12.1
       Compiling term v0.7.0
       Compiling syn v2.0.32
       Compiling http-body v0.4.5
       Compiling crossbeam-deque v0.8.3
       Compiling regex-automata v0.1.10
       Compiling idna v0.4.0
       Compiling is-terminal v0.4.9
       Compiling regex-automata v0.3.8
       Compiling addr2line v0.21.0
       Compiling ring v0.16.20
       Compiling backtrace v0.3.69
       Compiling num-complex v0.4.4
       Compiling rayon v1.7.0
       Compiling block-buffer v0.10.4
       Compiling crypto-common v0.1.6
       Compiling digest v0.10.7
       Compiling sha1 v0.10.5
       Compiling iso8601 v0.6.1
       Compiling matchers v0.1.0
       Compiling regex v1.9.5
       Compiling num v0.4.1
       Compiling fraction v0.13.1
       Compiling globset v0.4.13
       Compiling fancy-regex v0.11.0
       Compiling serde_derive_internals v0.26.0
       Compiling schemars_derive v0.8.13
       Compiling logos-derive v0.12.1
       Compiling structopt-derive v0.4.18
       Compiling clap_derive v3.2.25
       Compiling serde_derive v1.0.188
       Compiling tracing-attributes v0.1.26
       Compiling futures-macro v0.3.28
       Compiling tokio-macros v2.1.0
       Compiling thiserror-impl v1.0.48
       Compiling serde_repr v0.1.16
       Compiling async-recursion v1.0.5
       Compiling tokio v1.32.0
       Compiling tracing v0.1.37
       Compiling structopt v0.3.26
       Compiling tracing-subscriber v0.3.17
       Compiling logos v0.12.1
       Compiling sct v0.7.0
       Compiling rustls-webpki v0.101.5
       Compiling futures-executor v0.3.28
       Compiling futures v0.3.28
       Compiling tokio-util v0.7.8
       Compiling tokio-rustls v0.24.1
       Compiling url v2.4.1
       Compiling deranged v0.3.8
       Compiling serde_urlencoded v0.7.1
       Compiling csv v1.2.2
       Compiling toml v0.5.11
       Compiling hashbrown v0.12.3
       Compiling prettytable-rs v0.10.0
       Compiling rowan v0.15.11
       Compiling lru v0.7.8
       Compiling prettydiff v0.6.4
       Compiling lsp-types v0.93.2
       Compiling json_value_merge v1.2.0
       Compiling time v0.3.28
       Compiling h2 v0.3.21
       Compiling clap v3.2.25
       Compiling taplo v0.12.1
       Compiling jsonschema v0.17.1
       Compiling hyper v0.14.27
       Compiling hyper-rustls v0.24.1
       Compiling reqwest v0.11.20
       Compiling taplo-common v0.4.1
    error[E0308]: mismatched types
       --> /home/liam/.cargo/registry/src/index.crates.io-6f17d22bba15001f/taplo-common-0.4.1/src/schema/mod.rs:555:29
        |
    555 | ...                   Arc::try_unwrap(schema).unwrap()
        |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&Value`, found `Value`
        |
    note: return type inferred to be `&serde_json::Value` here
       --> /home/liam/.cargo/registry/src/index.crates.io-6f17d22bba15001f/taplo-common-0.4.1/src/schema/mod.rs:507:13
        |
    507 |             return;
        |             ^^^^^^
    help: consider borrowing here
        |
    555 |                             &Arc::try_unwrap(schema).unwrap()
        |                             +
    
    error[E0308]: mismatched types
       --> /home/liam/.cargo/registry/src/index.crates.io-6f17d22bba15001f/taplo-common-0.4.1/src/schema/mod.rs:557:29
        |
    557 | ...                   all_of.clone()
        |                       ^^^^^^^^^^^^^^ expected `&Value`, found `Value`
        |
    note: return type inferred to be `&serde_json::Value` here
       --> /home/liam/.cargo/registry/src/index.crates.io-6f17d22bba15001f/taplo-common-0.4.1/src/schema/mod.rs:507:13
        |
    507 |             return;
        |             ^^^^^^
    help: try removing the method call
        |
    557 -                             all_of.clone()
    557 +                             all_of
        |
    
    error[E0308]: mismatched types
       --> /home/liam/.cargo/registry/src/index.crates.io-6f17d22bba15001f/taplo-common-0.4.1/src/schema/mod.rs:562:37
        |
    562 |                 merged_all_of.merge(schema);
        |                               ----- ^^^^^^ expected `&Value`, found `Value`
        |                               |
        |                               arguments to this method are incorrect
        |
    note: method defined here
       --> /home/liam/.cargo/registry/src/index.crates.io-6f17d22bba15001f/json_value_merge-1.2.0/src/lib.rs:9:8
        |
    9   |     fn merge(&mut self, new_value: &Value);
        |        ^^^^^
    help: consider borrowing here
        |
    562 |                 merged_all_of.merge(&schema);
        |                                     +
    
    For more information about this error, try `rustc --explain E0308`.
    error: could not compile `taplo-common` (lib) due to 3 previous errors
    warning: build failed, waiting for other jobs to finish...
    error: failed to compile `taplo-cli v0.8.1`, intermediate artifacts can be found at `/tmp/cargo-install30EHc2`.
    To reuse those artifacts with a future compilation, set the environment variable `CARGO_TARGET_DIR` to that path.
    Check the log at /home/liam/.cache/pre-commit/pre-commit.log

    System info

Bug resulted on the following system:

redeboer commented 1 year ago

Hi @kbumsik, thanks for your report! I'm not too familiar with Rust, but it seems that something went wrong compiling Taplo (which is written in Rust), not in the pre-commit hook. Does it help to clean your pre-commit cache and compile again? (It will take some time though...) Maybe it also helps to remove your cargo directory (but again, I'm no Rust programmer, so I'm not sure if this affect any other work you are doing.) So:

rm -rf /home/liam/.cargo
pre-commit clean
pre-commit run -a
kbumsik commented 1 year ago

Hi, thanks for the quick reply.

Clearing and rebuilding does not help. Maybe I should report to the upstream then?

I am not familiar with Rust and Cargo neither, so I have no idea how to reproduce the building procedure without pre-commit. Is there any bare building commands without pre-commit so I could try reproduce and hopefully report upstream?

redeboer commented 1 year ago

Maybe I should report to the upstream then?

Probably better. For installation, you may find an answer here: https://taplo.tamasfe.dev/cli/installation/cargo.html https://doc.rust-lang.org/cargo/getting-started/installation.html

Btw, you can also try the taplo-docker hook. @m-roberts has implemented that and may have more info on how to get that to work.

redeboer commented 1 year ago

@kbumsik @christos-P @marionlb Could you give the hook a try again? There seem to have been some upstream updates and the hook is working again for me (tag v0.8.1).

You may need to clean up some caches first, see https://github.com/ComPWA/mirrors-taplo/issues/6#issuecomment-1717653407