From 1b1c48b1b62fb7841282e9a7b0913db8c85972de Mon Sep 17 00:00:00 2001 From: crowlkats Date: Tue, 26 Nov 2024 20:28:28 +0100 Subject: [PATCH] error rework --- Cargo.lock | 452 +++++++++++++++++++++++++++++++------ Cargo.toml | 18 +- examples/ddoc/main.rs | 4 +- lib/Cargo.toml | 6 +- lib/lib.rs | 32 ++- src/html/jsdoc.rs | 3 +- src/html/mod.rs | 12 +- src/html/render_context.rs | 3 +- src/html/search.rs | 2 +- src/lib.rs | 1 + src/parser.rs | 2 +- tests/html_test.rs | 11 +- 12 files changed, 443 insertions(+), 103 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 122a73c5..7ddbf269 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -71,9 +71,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.89" +version = "1.0.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" +checksum = "4c95c10ba0b00a02636238b814946408b1322d5ac4760326e6fb8ec956d85775" [[package]] name = "arrayvec" @@ -90,7 +90,7 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.79", + "syn 2.0.89", ] [[package]] @@ -101,7 +101,7 @@ checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.89", ] [[package]] @@ -193,6 +193,16 @@ dependencies = [ "generic-array", ] +[[package]] +name = "boxed_error" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17d4f95e880cfd28c4ca5a006cf7f6af52b4bcb7b5866f573b2faa126fb7affb" +dependencies = [ + "quote", + "syn 2.0.89", +] + [[package]] name = "bumpalo" version = "3.16.0" @@ -465,7 +475,7 @@ dependencies = [ "proc-macro2", "quote", "strsim 0.11.1", - "syn 2.0.79", + "syn 2.0.89", ] [[package]] @@ -476,7 +486,7 @@ checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" dependencies = [ "darling_core", "quote", - "syn 2.0.79", + "syn 2.0.89", ] [[package]] @@ -503,13 +513,14 @@ dependencies = [ [[package]] name = "deno_ast" -version = "0.43.3" +version = "0.44.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48d00b724e06d2081a141ec1155756a0b465d413d8e2a7515221f61d482eb2ee" +checksum = "eebc7aaabfdb3ddcad32aee1b62d250149dc8b35dfbdccbb125df2bdc62da952" dependencies = [ "base64", + "deno_error", "deno_media_type", - "deno_terminal", + "deno_terminal 0.2.0", "dprint-swc-ext", "once_cell", "percent-encoding", @@ -530,7 +541,7 @@ dependencies = [ "swc_visit", "swc_visit_macros", "text_lines", - "thiserror", + "thiserror 2.0.3", "unicode-width", "url", ] @@ -565,6 +576,7 @@ dependencies = [ "serde-wasm-bindgen", "serde_json", "termcolor", + "thiserror 2.0.3", "tokio", "url", "wasm-bindgen", @@ -577,6 +589,7 @@ dependencies = [ "anyhow", "console_error_panic_hook", "deno_doc", + "deno_error", "deno_graph", "import_map", "indexmap 2.6.0", @@ -584,20 +597,43 @@ dependencies = [ "pretty_assertions", "serde", "serde-wasm-bindgen", + "thiserror 2.0.3", "wasm-bindgen", "wasm-bindgen-futures", ] [[package]] -name = "deno_graph" -version = "0.85.0" +name = "deno_error" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d097305aba3f119781fe82b4d5a85a1ad10c586a388ee4d754e5bf82901cc5c" +checksum = "199c66ffd17ee1a948904d33f3d3f364573951c1f9fb3f859bfe7770bf33862a" +dependencies = [ + "deno_error_macro", + "libc", + "serde", + "serde_json", + "url", +] + +[[package]] +name = "deno_error_macro" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3cd99df6ae75443907e1f959fc42ec6dcea67a7bd083e76cf23a117102c9a2ce" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.89", +] + +[[package]] +name = "deno_graph" +version = "0.85.1" dependencies = [ - "anyhow", "async-trait", "data-url", "deno_ast", + "deno_error", "deno_semver", "deno_unsync", "encoding_rs", @@ -612,7 +648,7 @@ dependencies = [ "serde", "serde_json", "sha2", - "thiserror", + "thiserror 2.0.3", "url", "wasm_dep_analyzer", ] @@ -635,20 +671,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff25f6e08e7a0214bbacdd6f7195c7f1ebcd850c87a624e4ff06326b68b42d99" dependencies = [ "percent-encoding", - "thiserror", + "thiserror 1.0.64", "url", ] [[package]] name = "deno_semver" -version = "0.5.14" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "670fec7ef309384e23c2a90ac5d2d9d91a776d225306c75f5cdd28cf6cc8a59f" +checksum = "4756be7351289726087408984db18b9eb5e0186907673f39f858d119d0162071" dependencies = [ + "deno_error", "monch", "once_cell", "serde", - "thiserror", + "thiserror 2.0.3", "url", ] @@ -662,6 +699,16 @@ dependencies = [ "termcolor", ] +[[package]] +name = "deno_terminal" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daef12499e89ee99e51ad6000a91f600d3937fb028ad4918af76810c5bc9e0d5" +dependencies = [ + "once_cell", + "termcolor", +] + [[package]] name = "deno_unsync" version = "0.4.1" @@ -690,7 +737,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.89", ] [[package]] @@ -700,7 +747,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ab63b0e2bf4d5928aff72e83a7dace85d7bba5fe12dcc3c5a572d78caffd3f3c" dependencies = [ "derive_builder_core", - "syn 2.0.79", + "syn 2.0.89", ] [[package]] @@ -725,6 +772,17 @@ dependencies = [ "crypto-common", ] +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.89", +] + [[package]] name = "dprint-swc-ext" version = "0.20.0" @@ -781,10 +839,10 @@ checksum = "05b23dcc1b671771c6f59fdace6da685735c925f859733e8fd07fba6cae6462a" dependencies = [ "anyhow", "crossbeam-channel", - "deno_terminal", + "deno_terminal 0.1.1", "parking_lot", "regex", - "thiserror", + "thiserror 1.0.64", ] [[package]] @@ -810,7 +868,7 @@ checksum = "32016f1242eb82af5474752d00fd8ebcd9004bd69b462b1c91de833972d08ed4" dependencies = [ "proc-macro2", "swc_macros_common", - "syn 2.0.79", + "syn 2.0.89", ] [[package]] @@ -875,7 +933,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.89", ] [[package]] @@ -946,7 +1004,7 @@ dependencies = [ "pest_derive", "serde", "serde_json", - "thiserror", + "thiserror 1.0.64", ] [[package]] @@ -1015,6 +1073,124 @@ dependencies = [ "utf8-width", ] +[[package]] +name = "icu_collections" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db2fa452206ebee18c4b5c2274dbf1de17008e874b4dc4f0aea9d01ca79e4526" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locid" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13acbb8371917fc971be86fc8057c41a64b521c184808a698c02acc242dbf637" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_locid_transform" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01d11ac35de8e40fdeda00d9e1e9d92525f3f9d887cdd7aa81d727596788b54e" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_locid_transform_data", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_locid_transform_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fdc8ff3388f852bede6b579ad4e978ab004f139284d7b28715f773507b946f6e" + +[[package]] +name = "icu_normalizer" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19ce3e0da2ec68599d193c93d088142efd7f9c5d6fc9b803774855747dc6a84f" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "utf16_iter", + "utf8_iter", + "write16", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8cafbf7aa791e9b22bec55a167906f9e1215fd475cd22adfcf660e03e989516" + +[[package]] +name = "icu_properties" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93d6020766cfc6302c15dbbc9c8778c37e62c14427cb7f6e601d849e092aeef5" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_locid_transform", + "icu_properties_data", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67a8effbc3dd3e4ba1afa8ad918d5684b8868b3b26500753effea8d2eed19569" + +[[package]] +name = "icu_provider" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ed421c8a8ef78d3e2dbc98a973be2f3770cb42b606e3ab18d6237c4dfde68d9" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_provider_macros", + "stable_deref_trait", + "tinystr", + "writeable", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_provider_macros" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.89", +] + [[package]] name = "ident_case" version = "1.0.1" @@ -1023,12 +1199,23 @@ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" [[package]] name = "idna" -version = "0.5.0" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +checksum = "686f825264d630750a544639377bae737628043f20d38bbc029e8f29ea968a7e" dependencies = [ - "unicode-bidi", - "unicode-normalization", + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daca1df1c957320b2cf139ac61e7bd64fed304c5040df000a745aa1de3b4ef71" +dependencies = [ + "icu_normalizer", + "icu_properties", ] [[package]] @@ -1039,16 +1226,18 @@ checksum = "cb56e1aa765b4b4f3aadfab769793b7087bb03a4ea4920644a6d238e2df5b9ed" [[package]] name = "import_map" -version = "0.20.1" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "351a787decc56f38d65d16d32687265045d6d6a4531b4a0e1b649def3590354e" +checksum = "1215d4d92511fbbdaea50e750e91f2429598ef817f02b579158e92803b52c00a" dependencies = [ + "boxed_error", + "deno_error", "indexmap 2.6.0", "log", "percent-encoding", "serde", "serde_json", - "thiserror", + "thiserror 2.0.3", "url", ] @@ -1095,7 +1284,7 @@ dependencies = [ "Inflector", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.89", ] [[package]] @@ -1140,6 +1329,12 @@ version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" +[[package]] +name = "litemap" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ee93343901ab17bd981295f2cf0026d4ad018c7c31ba84549a4ddbb47a45104" + [[package]] name = "lock_api" version = "0.4.12" @@ -1309,7 +1504,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fdbef9d1d47087a895abd220ed25eb4ad973a5e26f6a4367b038c25e28dfc2d9" dependencies = [ "memchr", - "thiserror", + "thiserror 1.0.64", "ucd-trie", ] @@ -1333,7 +1528,7 @@ dependencies = [ "pest_meta", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.89", ] [[package]] @@ -1377,7 +1572,7 @@ dependencies = [ "phf_shared", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.89", ] [[package]] @@ -1441,9 +1636,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.87" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3e4daa0dcf6feba26f985457cdf104d4b4256fc5a09547140f3631bb076b19a" +checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" dependencies = [ "unicode-ident", ] @@ -1662,7 +1857,7 @@ checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.89", ] [[package]] @@ -1818,7 +2013,7 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.79", + "syn 2.0.89", ] [[package]] @@ -1931,7 +2126,7 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.79", + "syn 2.0.89", ] [[package]] @@ -2035,7 +2230,7 @@ checksum = "63db0adcff29d220c3d151c5b25c0eabe7e32dd936212b84cdaa1392e3130497" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.89", ] [[package]] @@ -2046,7 +2241,7 @@ checksum = "f486687bfb7b5c560868f69ed2d458b880cebc9babebcb67e49f31b55c5bf847" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.89", ] [[package]] @@ -2069,7 +2264,7 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.79", + "syn 2.0.89", ] [[package]] @@ -2085,15 +2280,26 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.79" +version = "2.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" +checksum = "44d46482f1c1c87acd84dea20c1bf5ebff4c757009ed6bf19cfd36fb10e92c4e" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] +[[package]] +name = "synstructure" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.89", +] + [[package]] name = "tap" version = "1.0.1" @@ -2139,7 +2345,16 @@ version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84" dependencies = [ - "thiserror-impl", + "thiserror-impl 1.0.64", +] + +[[package]] +name = "thiserror" +version = "2.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c006c85c7651b3cf2ada4584faa36773bd07bac24acfb39f3c431b36d7e667aa" +dependencies = [ + "thiserror-impl 2.0.3", ] [[package]] @@ -2150,7 +2365,28 @@ checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.89", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f077553d607adc1caf65430528a576c757a71ed73944b66ebb58ef2bbd243568" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.89", +] + +[[package]] +name = "tinystr" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9117f5d4db391c1cf6927e7bea3db74b9a1c1add8f7eda9ffd5364f40f57b82f" +dependencies = [ + "displaydoc", + "zerovec", ] [[package]] @@ -2204,7 +2440,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.89", ] [[package]] @@ -2226,7 +2462,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.89", ] [[package]] @@ -2266,12 +2502,6 @@ version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2896d95c02a80c6d6a5d6e953d479f5ddf2dfdb6a244441010e373ac0fb88971" -[[package]] -name = "unicode-bidi" -version = "0.3.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" - [[package]] name = "unicode-id" version = "0.3.5" @@ -2313,9 +2543,9 @@ checksum = "39ec24b3121d976906ece63c9daad25b85969647682eee313cb5779fdd69e14e" [[package]] name = "url" -version = "2.5.2" +version = "2.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +checksum = "32f8b686cadd1473f4bd0117a5d28d36b1ade384ea9b5069a1c40aefed7fda60" dependencies = [ "form_urlencoded", "idna", @@ -2323,12 +2553,24 @@ dependencies = [ "serde", ] +[[package]] +name = "utf16_iter" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8232dd3cdaed5356e0f716d285e4b40b932ac434100fe9b7e0e8e935b9e6246" + [[package]] name = "utf8-width" version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "86bd8d4e895da8537e5315b8254664e6b769c4ff3db18321b297a1e7004392e3" +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + [[package]] name = "utf8parse" version = "0.2.2" @@ -2411,7 +2653,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.89", "wasm-bindgen-shared", ] @@ -2445,7 +2687,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.89", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -2458,11 +2700,12 @@ checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" [[package]] name = "wasm_dep_analyzer" -version = "0.1.0" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f270206a91783fd90625c8bb0d8fbd459d0b1d1bf209b656f713f01ae7c04b8" +checksum = "2eeee3bdea6257cc36d756fa745a70f9d393571e47d69e0ed97581676a5369ca" dependencies = [ - "thiserror", + "deno_error", + "thiserror 2.0.3", ] [[package]] @@ -2588,6 +2831,18 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +[[package]] +name = "write16" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1890f4022759daae28ed4fe62859b1236caebfc61ede2f63ed4e695f3f6d936" + +[[package]] +name = "writeable" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51" + [[package]] name = "wyz" version = "0.5.1" @@ -2603,6 +2858,30 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cfe53a6657fd280eaa890a3bc59152892ffa3e30101319d168b781ed6529b049" +[[package]] +name = "yoke" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "120e6aef9aa629e3d4f52dc8cc43a015c7724194c97dfaf45180d2daf2b77f40" +dependencies = [ + "serde", + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2380878cad4ac9aac1e2435f3eb4020e8374b5f13c296cb75b4620ff8e229154" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.89", + "synstructure", +] + [[package]] name = "zerocopy" version = "0.7.35" @@ -2620,5 +2899,48 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.89", +] + +[[package]] +name = "zerofrom" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cff3ee08c995dee1859d998dea82f7374f2826091dd9cd47def953cae446cd2e" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "595eed982f7d355beb85837f651fa22e90b3c044842dc7f2c2842c086f295808" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.89", + "synstructure", +] + +[[package]] +name = "zerovec" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa2b893d79df23bfb12d5461018d408ea19dfafe76c2c7ef6d4eba614f8ff079" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.89", ] diff --git a/Cargo.toml b/Cargo.toml index 603f9f17..00c148ac 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,10 +11,13 @@ repository = "https://github.com/denoland/deno_doc" members = ["lib"] [workspace.dependencies] -deno_graph = { version = "0.85.0", default-features = false, features = ["symbols"] } -deno_ast = { version = "0.43.0" } -import_map = "0.20.0" +deno_graph = { version = "0.85.1", default-features = false, features = ["symbols"] } +deno_ast = { version = "0.44.0" } +thiserror = "2" +deno_error = "0.5.2" +import_map = "0.21.0" serde = { version = "1.0.204", features = ["derive"] } +indexmap = "2.3.0" [lib] crate-type = ["cdylib", "rlib"] @@ -25,14 +28,14 @@ name = "ddoc" required-features = ["comrak"] [dependencies] -anyhow = "1.0.86" cfg-if = "1.0.0" deno_ast.workspace = true deno_graph.workspace = true -indexmap = "2.3.0" +thiserror.workspace = true import_map.workspace = true lazy_static = "1.5.0" regex = "1.10.6" +indexmap.workspace = true serde.workspace = true serde_json = { version = "1.0.122", features = ["preserve_order"] } termcolor = "1.4.1" @@ -55,7 +58,7 @@ pretty_assertions = "1.4.0" insta = { version = "1.39.0", features = ["json"] } [target.'cfg(target_arch = "wasm32")'.dependencies] -url = "2.4.1" +url = "2.5.3" percent-encoding = "2.3.1" wasm-bindgen = "0.2.92" js-sys = "0.3.69" @@ -75,3 +78,6 @@ codegen-units = 1 incremental = true lto = true opt-level = "s" + +[patch.crates-io] +deno_graph = { path = "../deno_graph" } diff --git a/examples/ddoc/main.rs b/examples/ddoc/main.rs index 4c850c7f..ea298262 100644 --- a/examples/ddoc/main.rs +++ b/examples/ddoc/main.rs @@ -11,9 +11,9 @@ use deno_doc::DocNodeKind; use deno_doc::DocParser; use deno_doc::DocParserOptions; use deno_doc::DocPrinter; -use deno_graph::source::LoadFuture; use deno_graph::source::LoadResponse; use deno_graph::source::Loader; +use deno_graph::source::{LoadError, LoadFuture}; use deno_graph::BuildOptions; use deno_graph::CapturingModuleAnalyzer; use deno_graph::GraphKind; @@ -43,7 +43,7 @@ impl Loader for SourceFileLoader { content: content.into(), }) }) - .map_err(|err| err.into()) + .map_err(|err| LoadError::Other(std::sync::Arc::new(err))) } else { Ok(None) }; diff --git a/lib/Cargo.toml b/lib/Cargo.toml index a6ddd1c3..154b3e98 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -14,12 +14,14 @@ path = "lib.rs" crate-type = ["cdylib"] [dependencies] -anyhow = "1.0.86" +anyhow = "1.0.93" deno_graph = { workspace = true } +deno_error.workspace = true deno_doc = { path = "../", default-features = false } import_map.workspace = true +thiserror.workspace = true serde.workspace = true -indexmap = "2.6.0" +indexmap.workspace = true console_error_panic_hook = "0.1.7" js-sys = "=0.3.69" diff --git a/lib/lib.rs b/lib/lib.rs index 929f5446..cd55570c 100644 --- a/lib/lib.rs +++ b/lib/lib.rs @@ -7,6 +7,7 @@ use deno_doc::html::UsageComposerEntry; use deno_doc::html::UsageToMd; use deno_doc::DocParser; use deno_graph::source::CacheSetting; +use deno_graph::source::LoadError; use deno_graph::source::LoadFuture; use deno_graph::source::LoadOptions; use deno_graph::source::LoadResponse; @@ -59,6 +60,11 @@ impl Loader for JsLoader { specifier: &ModuleSpecifier, options: LoadOptions, ) -> LoadFuture { + #[derive(Debug, thiserror::Error, deno_error::JsError)] + #[class(generic)] + #[error("load rejected or errored")] + struct Reject; + #[derive(Serialize)] #[serde(rename_all = "camelCase")] struct JsLoadOptions { @@ -83,7 +89,7 @@ impl Loader for JsLoader { }; response .map(|value| serde_wasm_bindgen::from_value(value).unwrap()) - .map_err(|_| anyhow!("load rejected or errored")) + .map_err(|_| LoadError::Other(std::sync::Arc::new(Reject))) }; Box::pin(f) } @@ -108,7 +114,7 @@ impl Resolver for ImportMapResolver { self .0 .resolve(specifier, &referrer_range.specifier) - .map_err(|err| ResolveError::Other(err.into())) + .map_err(|err| ResolveError::Other(Box::new(err))) } } @@ -130,19 +136,27 @@ impl Resolver for JsResolver { referrer_range: &Range, _mode: deno_graph::source::ResolutionMode, ) -> Result { - use ResolveError::*; + #[derive(Debug, thiserror::Error, deno_error::JsError)] + #[class(generic)] + #[error("JavaScript resolve() function threw.")] + struct Reject; + + #[derive(Debug, thiserror::Error, deno_error::JsError)] + #[class(generic)] + #[error("{0}")] + struct WasmBindgen(String); + let this = JsValue::null(); let arg0 = JsValue::from(specifier); let arg1 = JsValue::from(referrer_range.specifier.to_string()); let value = match self.resolve.call2(&this, &arg0, &arg1) { Ok(value) => value, - Err(_) => { - return Err(Other(anyhow!("JavaScript resolve() function threw."))) - } + Err(_) => return Err(ResolveError::Other(Box::new(Reject))), }; let value: String = serde_wasm_bindgen::from_value(value) - .map_err(|err| anyhow!("{}", err))?; - ModuleSpecifier::parse(&value).map_err(|err| Other(err.into())) + .map_err(|err| Box::new(WasmBindgen(err.to_string())))?; + ModuleSpecifier::parse(&value) + .map_err(|err| ResolveError::Other(Box::new(err))) } } @@ -154,7 +168,7 @@ pub async fn doc( maybe_resolve: Option, maybe_import_map: Option, print_import_map_diagnostics: bool, -) -> anyhow::Result { +) -> Result { console_error_panic_hook::set_once(); inner_doc( root_specifier, diff --git a/src/html/jsdoc.rs b/src/html/jsdoc.rs index 83a4aca8..7a7b0d32 100644 --- a/src/html/jsdoc.rs +++ b/src/html/jsdoc.rs @@ -553,8 +553,7 @@ mod test { )], ), ]), - ) - .unwrap(); + ); let (a_short_path, nodes) = ctx.doc_nodes.first().unwrap(); diff --git a/src/html/mod.rs b/src/html/mod.rs index e7d56035..dc8d413b 100644 --- a/src/html/mod.rs +++ b/src/html/mod.rs @@ -72,7 +72,7 @@ const FUSE_FILENAME: &str = "fuse.js"; const SEARCH_JS: &str = include_str!("./templates/pages/search.js"); const SEARCH_FILENAME: &str = "search.js"; -fn setup_hbs() -> Result, anyhow::Error> { +fn setup_hbs() -> Result, handlebars::TemplateError> { let mut reg = Handlebars::new(); reg.register_escape_fn(|str| html_escape::encode_safe(str).into_owned()); reg.set_strict_mode(true); @@ -282,7 +282,7 @@ impl GenerateCtx { common_ancestor: Option, file_mode: FileMode, doc_nodes_by_url: IndexMap>, - ) -> Result { + ) -> Self { let mut main_entrypoint = None; let doc_nodes = doc_nodes_by_url @@ -364,7 +364,7 @@ impl GenerateCtx { }) .collect::>(); - Ok(Self { + Self { package_name: options.package_name, common_ancestor, doc_nodes, @@ -380,7 +380,7 @@ impl GenerateCtx { markdown_renderer: options.markdown_renderer, markdown_stripper: options.markdown_stripper, head_inject: options.head_inject, - }) + } } pub fn render( @@ -797,7 +797,7 @@ pub enum FileMode { pub fn generate( mut options: GenerateOptions, doc_nodes_by_url: IndexMap>, -) -> Result, anyhow::Error> { +) -> Result, serde_json::Error> { if doc_nodes_by_url.len() == 1 && options.main_entrypoint.is_none() { options.main_entrypoint = Some(doc_nodes_by_url.keys().next().unwrap().clone()); @@ -817,7 +817,7 @@ pub fn generate( let common_ancestor = find_common_ancestor(doc_nodes_by_url.keys(), true); let ctx = - GenerateCtx::new(options, common_ancestor, file_mode, doc_nodes_by_url)?; + GenerateCtx::new(options, common_ancestor, file_mode, doc_nodes_by_url); let mut files = HashMap::new(); // Index page diff --git a/src/html/render_context.rs b/src/html/render_context.rs index bfe735ed..a79a5185 100644 --- a/src/html/render_context.rs +++ b/src/html/render_context.rs @@ -606,8 +606,7 @@ mod test { None, Default::default(), doc_nodes_by_url, - ) - .unwrap(); + ); let (short_path, doc_nodes) = ctx.doc_nodes.first().unwrap(); diff --git a/src/html/search.rs b/src/html/search.rs index af54a7da..4ab2e1b0 100644 --- a/src/html/search.rs +++ b/src/html/search.rs @@ -126,7 +126,7 @@ pub fn generate_search_index(ctx: &GenerateCtx) -> serde_json::Value { pub(crate) fn get_search_index_file( ctx: &GenerateCtx, -) -> Result { +) -> Result { let search_index = generate_search_index(ctx); let search_index_str = serde_json::to_string(&search_index)?; diff --git a/src/lib.rs b/src/lib.rs index ccc1bce4..70d36108 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,6 +5,7 @@ #![deny(clippy::disallowed_types)] #![deny(clippy::print_stderr)] #![deny(clippy::print_stdout)] +#![deny(clippy::unnecessary_wraps)] #[macro_use] extern crate cfg_if; diff --git a/src/parser.rs b/src/parser.rs index b8d77687..87dbfae0 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -134,7 +134,7 @@ impl<'a> DocParser<'a> { graph: &'a ModuleGraph, parser: &'a dyn EsParser, options: DocParserOptions, - ) -> Result { + ) -> Result { let root_symbol = Rc::new(deno_graph::symbols::RootSymbol::new(graph, parser)); let visibility = SymbolVisibility::build(graph, &root_symbol)?; diff --git a/tests/html_test.rs b/tests/html_test.rs index 4e0a27cc..45f225bd 100644 --- a/tests/html_test.rs +++ b/tests/html_test.rs @@ -37,7 +37,7 @@ impl Loader for SourceFileLoader { content: content.into(), }) }) - .map_err(|err| err.into()) + .map_err(|err| std::sync::Arc::new(err).into()) } else { Ok(None) }; @@ -366,8 +366,7 @@ async fn symbol_group() { None, Default::default(), doc_nodes_by_url, - ) - .unwrap(); + ); let mut files = vec![]; @@ -457,8 +456,7 @@ async fn symbol_search() { None, Default::default(), doc_nodes_by_url, - ) - .unwrap(); + ); let search_index = generate_search_index(&ctx); @@ -505,8 +503,7 @@ async fn module_doc() { None, FileMode::Single, doc_nodes_by_url, - ) - .unwrap(); + ); let mut module_docs = vec![];