From 50ad9417e3993e93ebb58603d999a7bc451f14a3 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Fri, 21 Aug 2026 15:04:14 -0400 Subject: [PATCH 1/2] chore: upgrade to dprint-core 0.69.0 --- Cargo.lock | 300 ++++++++++++++++++++++++++++++++----------------- Cargo.toml | 5 +- src/handler.rs | 75 +++++++------ src/main.rs | 4 +- tests/tests.rs | 1 + 5 files changed, 244 insertions(+), 141 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 740c03f..e8a6c2f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,18 +17,6 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" -[[package]] -name = "ahash" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" -dependencies = [ - "cfg-if", - "once_cell", - "version_check", - "zerocopy", -] - [[package]] name = "aho-corasick" version = "1.1.3" @@ -58,7 +46,7 @@ checksum = "6e0c28dcc82d7c8ead5cb13beb15405b57b8546e93215673ff8ca0349a028107" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.119", ] [[package]] @@ -109,9 +97,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.16.0" +version = "3.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" +checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649" dependencies = [ "allocator-api2", ] @@ -136,15 +124,14 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "console" -version = "0.15.8" +version = "0.16.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e1f83fc076bd6dd27517eacdf25fef6c4dfe5f1d7448bafaaf3a26f13b5e4eb" +checksum = "4fe5f465a4f6fee88fad41b85d990f84c835335e85b5d9e6e63e0d06d28cba7c" dependencies = [ "encode_unicode", - "lazy_static", "libc", "unicode-width", - "windows-sys", + "windows-sys 0.61.2", ] [[package]] @@ -158,9 +145,28 @@ dependencies = [ [[package]] name = "crossbeam-channel" -version = "0.5.13" +version = "0.5.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d85363c37faeca707aef026efa9f3b34d077bce547e48f770770625c6013679e" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33480d6946193aa8033910124896ca395333cae7e2d1113d1fef6c3272217df2" +checksum = "5181e0de7b61eb03a81e347d6dd8797bae9da5146707b51077e2d71a54ec0ceb" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d6914041f254d6e9176c01941b21115dcfb7089e55135a35411081bd106ef3f" dependencies = [ "crossbeam-utils", ] @@ -183,9 +189,9 @@ dependencies = [ [[package]] name = "deno_terminal" -version = "0.1.1" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e6337d4e7f375f8b986409a76fbeecfa4bd8a1343e63355729ae4befa058eaf" +checksum = "f3ba8041ae7319b3ca6a64c399df4112badcbbe0868b4517637647614bede4be" dependencies = [ "once_cell", "termcolor", @@ -209,22 +215,22 @@ dependencies = [ [[package]] name = "dprint-core" -version = "0.67.0" +version = "0.69.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2309841cd79a9c60d2976f46b2df63d9a1a52211a3c62424e1e105b52dd5c436" +checksum = "7554bfc77a03c35c5581d5f390b7f102c501e37841f7f43d29dd54a0b3c2284d" dependencies = [ - "anyhow", "async-trait", "bumpalo", "crossbeam-channel", "futures", - "hashbrown", + "hashbrown 0.15.5", "indexmap", "libc", "parking_lot", "rustc-hash", "serde", "serde_json", + "thiserror 2.0.18", "tokio", "tokio-util", "unicode-width", @@ -233,11 +239,10 @@ dependencies = [ [[package]] name = "dprint-development" -version = "0.10.1" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12bc835c6195bc3bd68ccc71b86ccb33cc2e9253cfc875bc371acea1ff034268" +checksum = "90b3b095f94733262261bfeb860a6550e1d656dd108240c43004bd0f1b419837" dependencies = [ - "anyhow", "console", "file_test_runner", "serde_json", @@ -248,7 +253,6 @@ dependencies = [ name = "dprint-plugin-exec" version = "0.7.3" dependencies = [ - "anyhow", "dprint-core", "dprint-development", "globset", @@ -261,11 +265,17 @@ dependencies = [ "tokio", ] +[[package]] +name = "either" +version = "1.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "252afb9ae5eaa683babdc6a068b3f5726eb19e05070c731f9b2a23a7c3e8ed34" + [[package]] name = "encode_unicode" -version = "0.3.6" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" +checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0" [[package]] name = "equivalent" @@ -275,18 +285,25 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "file_test_runner" -version = "0.5.1" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5eedfda6f865129a89c9cf35dc8203aaed94adf3ac42c2d8d7769ac32ca290d" +checksum = "aab2ea62262e650557af93e48bfb0ffbcf3b6d86af4b9fea1aa00f93821b69a9" dependencies = [ "anyhow", "crossbeam-channel", "deno_terminal", "parking_lot", + "rayon", "regex", - "thiserror", + "thiserror 2.0.18", ] +[[package]] +name = "foldhash" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" + [[package]] name = "futures" version = "0.3.30" @@ -343,7 +360,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.119", ] [[package]] @@ -416,28 +433,42 @@ dependencies = [ "pest_derive", "serde", "serde_json", - "thiserror", + "thiserror 1.0.61", ] [[package]] name = "hashbrown" -version = "0.14.5" +version = "0.15.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" +checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" dependencies = [ - "ahash", "allocator-api2", + "equivalent", + "foldhash", ] +[[package]] +name = "hashbrown" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" + +[[package]] +name = "hermit-abi" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c" + [[package]] name = "indexmap" -version = "2.2.6" +version = "2.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" +checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9" dependencies = [ "equivalent", - "hashbrown", + "hashbrown 0.17.1", "serde", + "serde_core", ] [[package]] @@ -446,12 +477,6 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" -[[package]] -name = "lazy_static" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" - [[package]] name = "libc" version = "0.2.155" @@ -489,6 +514,16 @@ dependencies = [ "adler", ] +[[package]] +name = "num_cpus" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91df4bbde75afed763b708b7eee1e8e7651e02d97f6d5dd763e89367e957b23b" +dependencies = [ + "hermit-abi", + "libc", +] + [[package]] name = "object" version = "0.36.1" @@ -534,7 +569,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cd53dff83f26735fdc1ca837098ccf133605d794cdae66acfc2bfac3ec809d95" dependencies = [ "memchr", - "thiserror", + "thiserror 1.0.61", "ucd-trie", ] @@ -558,7 +593,7 @@ dependencies = [ "pest_meta", "proc-macro2", "quote", - "syn", + "syn 2.0.119", ] [[package]] @@ -596,9 +631,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.86" +version = "1.0.107" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9" dependencies = [ "unicode-ident", ] @@ -612,6 +647,26 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rayon" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb39b166781f92d482534ef4b4b1b2568f42613b53e5b6c160e24cfbfa30926d" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22e18b0f0062d30d4230b2e85ff77fdfe4326feb054b9783a3460d8435c8ab91" +dependencies = [ + "crossbeam-deque", + "crossbeam-utils", +] + [[package]] name = "redox_syscall" version = "0.5.2" @@ -623,9 +678,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.10.5" +version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f" +checksum = "f020237b6c8eed93db2e2cb53c00c60a8e1bc73da7d073199a1180401450218d" dependencies = [ "aho-corasick", "memchr", @@ -635,9 +690,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.7" +version = "0.4.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" +checksum = "ad8553b9b26413251cbf30e620595c7a41b3887f03da04579c0e6b0d6a06b4b2" dependencies = [ "aho-corasick", "memchr", @@ -646,9 +701,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.4" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" +checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4" [[package]] name = "rustc-demangle" @@ -658,15 +713,9 @@ checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] name = "rustc-hash" -version = "1.1.0" +version = "2.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" - -[[package]] -name = "ryu" -version = "1.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" +checksum = "6b1e7f9a428571be2dc5bc0505c13fb6bf936822b894ec87abf8a08a4e51742d" [[package]] name = "scopeguard" @@ -676,34 +725,46 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "serde" -version = "1.0.204" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.229" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc76f558e0cbb2a839d37354c575f1dc3fdc6546b5be373ba43d95f231bf7c12" +checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.204" +version = "1.0.229" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222" +checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 3.0.3", ] [[package]] name = "serde_json" -version = "1.0.120" +version = "1.0.151" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e0d21c9a8cae1235ad58a00c11cb40d4b1e5c784f1ef2c537876ed6ffd8b7c5" +checksum = "c841b55ecdae098c80dcae9cf767f6f8a0c2cdb3416bbef72181df4d0fe73f14" dependencies = [ "indexmap", "itoa", - "ryu", + "memchr", "serde", + "serde_core", + "zmij", ] [[package]] @@ -719,9 +780,9 @@ dependencies = [ [[package]] name = "similar" -version = "2.5.0" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa42c91313f1d05da9b26f267f931cf178d4aba455b4c4622dd7355eb80c6640" +checksum = "bbbb5d9659141646ae647b42fe094daf6c6192d1620870b449d9557f748b2daa" [[package]] name = "slab" @@ -746,9 +807,20 @@ checksum = "8dae68aa5bd5dc2d3a2137b0f6bcdd8255dce1983dc155fe0246572e179c9c3a" [[package]] name = "syn" -version = "2.0.70" +version = "2.0.119" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "3.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f0209b68b3613b093e0ec905354eccaedcfe83b8cb37cbdeae64026c3064c16" +checksum = "53e9bae58849f64dfa4f5d5ae372c8341f7305f82a3868709269343628b659a3" dependencies = [ "proc-macro2", "quote", @@ -770,7 +842,16 @@ version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709" dependencies = [ - "thiserror-impl", + "thiserror-impl 1.0.61", +] + +[[package]] +name = "thiserror" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" +dependencies = [ + "thiserror-impl 2.0.18", ] [[package]] @@ -781,7 +862,18 @@ checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.119", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", ] [[package]] @@ -791,6 +883,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" dependencies = [ "backtrace", + "num_cpus", "pin-project-lite", "tokio-macros", ] @@ -803,7 +896,7 @@ checksum = "5f5ae998a069d4b5aba8ee9dad856af7d520c3699e6159b185c2acd48155d39a" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.119", ] [[package]] @@ -839,9 +932,9 @@ checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unicode-width" -version = "0.1.13" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" +checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254" [[package]] name = "version_check" @@ -871,7 +964,7 @@ version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b" dependencies = [ - "windows-sys", + "windows-sys 0.52.0", ] [[package]] @@ -880,6 +973,12 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + [[package]] name = "windows-sys" version = "0.52.0" @@ -889,6 +988,15 @@ dependencies = [ "windows-targets", ] +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + [[package]] name = "windows-targets" version = "0.52.6" @@ -960,21 +1068,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" [[package]] -name = "zerocopy" -version = "0.7.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" -dependencies = [ - "zerocopy-derive", -] - -[[package]] -name = "zerocopy-derive" -version = "0.7.35" +name = "zmij" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] +checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b" diff --git a/Cargo.toml b/Cargo.toml index 3b2b5f0..270673d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,8 +18,7 @@ overflow-checks = false panic = "abort" [dependencies] -anyhow = "1.0.86" -dprint-core = { version = "0.67.0", features = ["process"] } +dprint-core = { version = "0.69.0", features = ["process"] } globset = "0.4.14" handlebars = "5.1.2" serde = { version = "1.0.204", features = ["derive"] } @@ -28,6 +27,6 @@ splitty = "1.0.1" tokio = { version = "1.38.0", features = ["time"] } [dev-dependencies] -dprint-development = "0.10.1" +dprint-development = "0.11.0" pretty_assertions = "1.4.0" serde_json = "1.0.120" diff --git a/src/handler.rs b/src/handler.rs index a4d2716..c27d748 100644 --- a/src/handler.rs +++ b/src/handler.rs @@ -13,10 +13,6 @@ use std::rc::Rc; use std::sync::Arc; use std::time::Duration; -use anyhow::Error; -use anyhow::Result; -use anyhow::anyhow; -use anyhow::bail; use dprint_core::async_runtime::LocalBoxFuture; use dprint_core::async_runtime::async_trait; use dprint_core::configuration::ConfigKeyMap; @@ -24,6 +20,7 @@ use dprint_core::configuration::GlobalConfiguration; use dprint_core::plugins::AsyncPluginHandler; use dprint_core::plugins::CancellationToken; use dprint_core::plugins::FileMatchingInfo; +use dprint_core::plugins::FormatError; use dprint_core::plugins::FormatRequest; use dprint_core::plugins::FormatResult; use dprint_core::plugins::HostFormatRequest; @@ -199,7 +196,7 @@ pub async fn format_bytes( .stderr(Stdio::piped()) .args(args) .spawn() - .map_err(|e| anyhow!("Cannot start formatter process: {}", e))?, + .map_err(|e| FormatError::new(format!("Cannot start formatter process: {}", e)))?, ); // capturing stdout @@ -211,7 +208,9 @@ pub async fn format_bytes( })); } else { let _ = child.kill(); - return Err(anyhow!("Formatter did not have a handle for stdout")); + return Err(FormatError::new( + "Formatter did not have a handle for stdout", + )); } // capturing stderr @@ -228,25 +227,25 @@ pub async fn format_bytes( .stdin .take() .ok_or_else(|| { - anyhow!( + FormatError::new( "Cannot open the command's stdin. Perhaps you meant to set the command's \"stdin\" configuration to false?", ) })?; let file_bytes = file_bytes.into_owned(); dprint_core::async_runtime::spawn_blocking(move || { - stdin - .write_all(&file_bytes) - .map_err(|err| anyhow!("Cannot write into the command's stdin. {}", err)) + stdin.write_all(&file_bytes).map_err(|err| { + FormatError::new(format!("Cannot write into the command's stdin. {}", err)) + }) }) .await??; } let child_completed = dprint_core::async_runtime::spawn_blocking(move || match child.wait() { Ok(status) => Ok(status), - Err(e) => Err(anyhow!( + Err(e) => Err(FormatError::new(format!( "Error while waiting for formatter to complete: {}", e - )), + ))), }); let result_future = async { @@ -258,7 +257,7 @@ pub async fn format_bytes( for handle_result in handle_results { handle_result??; // surface any errors capturing } - Ok::<_, Error>((output, exit_status)) + Ok::<_, FormatError>((output, exit_status)) }; tokio::select! { @@ -283,13 +282,13 @@ pub async fn format_bytes( && trim_bytes_len(&file_bytes) == 0 { // prevent someone formatting all their files to empty files - bail!( + return Err(FormatError::new(format!( concat!( "The original file text was greater than {} characters, but the formatted text was empty. ", "Perhaps dprint-plugin-exec has been misconfigured?", ), MIN_CHARS_TO_EMPTY - ) + ))); } else { Some(file_bytes.into_owned()) }) @@ -298,9 +297,11 @@ pub async fn format_bytes( fn select_commands<'a>( config: &'a Configuration, file_path: &Path, -) -> Result> { +) -> Result, FormatError> { if !config.is_valid { - bail!("Cannot format because the configuration was not valid."); + return Err(FormatError::new( + "Cannot format because the configuration was not valid.", + )); } let mut binaries = Vec::new(); @@ -323,11 +324,11 @@ async fn handle_child_exit_status( ok_text: Vec, err_rx: Receiver>, exit_status: ExitStatus, -) -> Result, Error> { +) -> Result, FormatError> { if exit_status.success() { return Ok(ok_text); } - Err(anyhow!( + Err(FormatError::new(format!( "Child process exited with code {}: {}", exit_status.code().unwrap(), String::from_utf8_lossy( @@ -335,14 +336,14 @@ async fn handle_child_exit_status( .await .expect("Could not propagate error message from child process") ) - )) + ))) } -fn timeout_err(config: &Configuration) -> Error { - anyhow!( +fn timeout_err(config: &Configuration) -> FormatError { + FormatError::new(format!( "Child process has not returned a result within {} seconds.", config.timeout, - ) + )) } /// Remembers which setup commands have already been run so that a command's @@ -360,7 +361,7 @@ enum SetupRun { enum SetupInitError { Cancelled, - Failed(Error), + Failed(FormatError), } impl SetupState { @@ -369,7 +370,7 @@ impl SetupState { cwd: &Path, setup_command: &SetupCommand, token: &Arc, - ) -> Result { + ) -> Result { // the cwd is part of the key because the same command run in different // directories may produce different results let key = format!( @@ -410,7 +411,12 @@ async fn run_setup_command( .stderr(Stdio::piped()) .args(&setup_command.args) .spawn() - .map_err(|e| SetupInitError::Failed(anyhow!("Cannot start setup command process: {}", e)))?, + .map_err(|e| { + SetupInitError::Failed(FormatError::new(format!( + "Cannot start setup command process: {}", + e + ))) + })?, ); // capture stderr to surface it if the command fails @@ -423,9 +429,12 @@ async fn run_setup_command( } let child_completed = dprint_core::async_runtime::spawn_blocking(move || { - child - .wait() - .map_err(|e| anyhow!("Error while waiting for setup command to complete: {}", e)) + child.wait().map_err(|e| { + FormatError::new(format!( + "Error while waiting for setup command to complete: {}", + e + )) + }) }); let result_future = async { @@ -435,14 +444,14 @@ async fn run_setup_command( for handle_result in handle_results { handle_result??; // surface any errors capturing } - Ok::<_, Error>(exit_status) + Ok::<_, FormatError>(exit_status) }; tokio::select! { _ = token.wait_cancellation() => Err(SetupInitError::Cancelled), result = result_future => match result { Ok(exit_status) if exit_status.success() => Ok(()), - Ok(exit_status) => Err(SetupInitError::Failed(anyhow!( + Ok(exit_status) => Err(SetupInitError::Failed(FormatError::new(format!( "Setup command '{}' exited with code {}: {}", setup_command.executable, exit_status @@ -450,13 +459,13 @@ async fn run_setup_command( .map(|code| code.to_string()) .unwrap_or_else(|| "unknown".to_string()), String::from_utf8_lossy(&err_rx.await.unwrap_or_default()) - ))), + )))), Err(err) => Err(SetupInitError::Failed(err)), } } } -fn read_stream_lines(mut readable: R, sender: Sender>) -> Result<(), Error> +fn read_stream_lines(mut readable: R, sender: Sender>) -> Result<(), FormatError> where R: std::io::Read + Unpin, { diff --git a/src/main.rs b/src/main.rs index 5bfb8a4..3dcea05 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,10 +1,10 @@ -use anyhow::Result; +use dprint_core::plugins::FormatError; use dprint_core::plugins::process::get_parent_process_id_from_cli_args; use dprint_core::plugins::process::handle_process_stdio_messages; use dprint_core::plugins::process::start_parent_process_checker_task; use dprint_plugin_exec::handler::ExecHandler; -fn main() -> Result<()> { +fn main() -> Result<(), FormatError> { let rt = tokio::runtime::Builder::new_current_thread() .enable_time() .build() diff --git a/tests/tests.rs b/tests/tests.rs index bed6420..34dcd3b 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -53,6 +53,7 @@ fn test_specs() { ) .await .map(|maybe_bytes| maybe_bytes.map(|bytes| String::from_utf8(bytes).unwrap())) + .map_err(Into::into) }) }), Arc::new(move |_file_name, _file_text, _spec_config| panic!("Not supported.")), From a182d0eebf3c8a9bf7266ffd85b76d18c0073de2 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Fri, 21 Aug 2026 15:22:47 -0400 Subject: [PATCH 2/2] chore: use dprint-core 0.69.1 --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e8a6c2f..974ec10 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -215,9 +215,9 @@ dependencies = [ [[package]] name = "dprint-core" -version = "0.69.0" +version = "0.69.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7554bfc77a03c35c5581d5f390b7f102c501e37841f7f43d29dd54a0b3c2284d" +checksum = "67359cea061dd052fca921d3589a9ce59bc16fa23bfb9d06d5c669a1dbd23915" dependencies = [ "async-trait", "bumpalo", diff --git a/Cargo.toml b/Cargo.toml index 270673d..48e2542 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ overflow-checks = false panic = "abort" [dependencies] -dprint-core = { version = "0.69.0", features = ["process"] } +dprint-core = { version = "0.69.1", features = ["process"] } globset = "0.4.14" handlebars = "5.1.2" serde = { version = "1.0.204", features = ["derive"] }